﻿using CIS.DB;
using CIS.Web.Common;
using CIS.Web.Models;
using CIS.Web.Properties;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;
using NPOI.OpenXmlFormats.Wordprocessing;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.XWPF.UserModel;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using static System.Net.Mime.MediaTypeNames;

namespace CIS.Web.Controllers
{
	[RoutePrefix("ConferenceSchedule")]
	public class ConferenceScheduleController : BaseDbController
	{
		private TimeSpan _startTime = new TimeSpan(0);
		private double _durationForenoon = 0;
		private double _durationAfternoon = 0;
		private double _durationEvening = 0;

		[Route("Index/{ConferenceId}")]
		public async Task<ActionResult> Index(string conferenceId)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", conferenceId);

			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == conferenceId);

			ViewBag.ConferenceId = conferenceId;
			ViewBag.ConferenceName = conferenceMaster.ConferenceName;
			ViewBag.ControllerName = Resources.ConferenceSchedule;
			ViewBag.Language = conferenceMaster.IsInternational ? ConstValues.Language.En : ConstValues.Language.Cn;

			var model = new ConferenceScheduleModel();
			model.ConferenceId = conferenceId;
			LoginUser.ConferenceFunctionIdList = Utility.GetConferenceFunctionIdList(conferenceId);
			return View(model);
		}

		public async Task<JsonCamelCaseResult> GetData(int? page, int? rows, string sort, string order, ConferenceScheduleModel model)
		{
			int take = rows ?? ConstValues.DefaultGridRows;
			int skip = ((page ?? 1) - 1) * take;

			var sql = DbContext.ScheduleMaster.AsNoTracking()
					.Where(x => !string.IsNullOrEmpty(x.Status) &&
						x.ConferenceId == model.ConferenceId);

			if (!string.IsNullOrWhiteSpace(model.SelSchedulePlace))
			{
				sql = sql.Where(x => x.SchedulePlace.Contains(model.SelSchedulePlace));
			}

			int total = await sql.CountAsync();

			if (!string.IsNullOrEmpty(sort))
			{
				sql = sql.OrderBy(sort + ConstValues.chrSpace + order).Skip(skip).Take(take);
			}
			else
			{
				sql = sql.OrderBy(x => x.Sort).ThenByDescending(x => x.UpdateDate).ThenBy(x => x.SchedulePlace).Skip(skip).Take(take);
			}

			var sqlResult = await sql.ToListAsync();

			var result = new List<ConferenceScheduleModel>();
			sqlResult.ForEach(y =>
			{
				var topicList = DbContext.ScheduleTopicMaster.AsNoTracking()
						.Where(x => x.Status == ConstValues.Status.正常 &&
							x.ScheduleId == y.ID)
						.Join(DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常),
							schedule => schedule.TopicId,
							topic => topic.ID,
							(schedule, topic) => new
							{
								TopicName = topic.TopicName
							})
						.OrderBy(x => x.TopicName)
						.Select(x => x.TopicName)
						.Distinct()
						.ToList();

				result.Add(new ConferenceScheduleModel()
				{
					Id = y.ID,
					ConferenceId = y.ConferenceId,
					SchedulePlace = y.SchedulePlace,
					TopicName = string.Join(ConstValues.strHtmlNewline, topicList),
					Status = y.Status,
					Sort = y.Sort,
					Remark = y.Remark,
					Creator = y.Creator,
					CreateIP = y.CreateIP,
					CreateDate = Request.Cookies["_culture"].Value == ConstValues.Language.Cn ?
							y.CreateDate.Value.ToString("yyyy-MM-dd") :
							y.CreateDate.Value.ToString("MM/dd/yyyy")
				});
			});

			return JsonCamelCase(new
			{
				Total = total,
				Rows = result,
			},
			JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetEditData(string id)
		{
			var result = await DbContext.ScheduleMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == id);

			if (result != null)
			{
				return JsonCamelCase(Utility.CreateSuccessJsonResult(string.Empty, result),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("Create/{ConferenceId}")]
		public async Task<JsonResult> Create(ConferenceScheduleModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ScheduleMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ConferenceId == model.ConferenceId &&
						x.SchedulePlace == model.SchedulePlace);
			if (result != null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(
						string.Format(Resources.MsgRecordExist, Resources.SchedulePlace)),
						JsonRequestBehavior.AllowGet);
			}

			var scheduleMaster = new ScheduleMaster
			{
				ID = Utility.GetTableId(ConstValues.TableName.ScheduleMaster),
				ConferenceId = model.ConferenceId,
				SchedulePlace = model.SchedulePlace,
				Status = model.Status,
				Sort = model.Sort.HasValue ? model.Sort.Value : ConstValues.DefaultSort,
				Remark = model.Remark?.Trim(),
				Creator = LoginUser.UserName,
				CreateIP = LoginUser.IP,
				CreateDate = DateTime.Now
			};

			DbContext.ScheduleMaster.Add(scheduleMaster);
			await DbContext.SaveChangesAsync();

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
					JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("Modify/{ConferenceId}")]
		public async Task<JsonResult> Modify(ConferenceScheduleModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var exist = await DbContext.ScheduleMaster
					.FirstOrDefaultAsync(x => x.ID != model.Id &&
						x.ConferenceId == model.ConferenceId &&
						x.SchedulePlace == model.SchedulePlace);

			if (exist != null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(
						string.Format(Resources.MsgRecordExist, Resources.SchedulePlace)),
						JsonRequestBehavior.AllowGet);
			}

			var result = await DbContext.ScheduleMaster
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				result.SchedulePlace = model.SchedulePlace?.Trim();
				result.Status = model.Status;
				result.Sort = model.Sort.HasValue ? model.Sort.Value : ConstValues.DefaultSort;
				result.Remark = model.Remark?.Trim();
				result.Updater = LoginUser.UserName;
				result.UpdateIP = LoginUser.IP;
				result.UpdateDate = DateTime.Now;

				await DbContext.SaveChangesAsync();

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("Delete/{ConferenceId}")]
		public async Task<JsonResult> Delete(ConferenceScheduleModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var exist = await DbContext.ScheduleInfo.AsNoTracking()
					.Where(x => x.ScheduleId == model.Id).ToListAsync();

			if (exist.Count > 0)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgUsingCanNotDelete),
						JsonRequestBehavior.AllowGet);
			}

			var result = await DbContext.ScheduleMaster
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				DbContext.ScheduleMaster.Remove(result);
				await DbContext.SaveChangesAsync();

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessDelete),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		public async Task<JsonCamelCaseResult> GetDateTopicData(string scheduleId)
		{
			var sqlResult = await DbContext.ScheduleDateMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ScheduleId == scheduleId)
					.OrderBy(x => x.ScheduleDate)
					.ToListAsync();

			var result = new List<ConferenceScheduleDateModel>();
			sqlResult.ForEach(y =>
			{
				var topicList = DbContext.ScheduleTopicMaster.AsNoTracking()
						.Where(x => x.Status == ConstValues.Status.正常 &&
							x.ScheduleId == y.ScheduleId &&
							x.ScheduleDate == y.ScheduleDate)
						.Join(DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常),
							schedule => schedule.TopicId,
							topic => topic.ID,
							(schedule, topic) => new
							{
								TopicName = topic.TopicName
							})
						.OrderBy(x => x.TopicName)
						.Select(x => x.TopicName)
						.ToList();

				result.Add(new ConferenceScheduleDateModel()
				{
					Id = y.ID,
					ScheduleId = y.ScheduleId,
					ScheduleDay = Request.Cookies["_culture"].Value == ConstValues.Language.Cn ? y.ScheduleDate.ToString("yyyy-MM-dd") : y.ScheduleDate.ToString("MM/dd/yyyy"),
					Forenoon = !(y.ForenoonStartTime.HasValue && y.ForenoonEndTime.HasValue) ? string.Empty :
							y.ForenoonStartTime.ToString().Substring(0, 5) + ConstValues.strHyphen + y.ForenoonEndTime.Value.ToString().Substring(0, 5),
					Afternoon = !(y.AfternoonStartTime.HasValue && y.AfternoonEndTime.HasValue) ? string.Empty :
							y.AfternoonStartTime.ToString().Substring(0, 5) + ConstValues.strHyphen + y.AfternoonEndTime.Value.ToString().Substring(0, 5),
					Evening = !(y.EveningStartTime.HasValue && y.EveningEndTime.HasValue) ? string.Empty :
							y.EveningStartTime.ToString().Substring(0, 5) + ConstValues.strHyphen + y.EveningEndTime.Value.ToString().Substring(0, 5),
					TopicName = string.Join(ConstValues.strHtmlNewline, topicList),
					Remark = y.Remark
				});
			});

			return JsonCamelCase(new
			{
				Rows = result,
			},
			JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetEditDateTopicData(string id)
		{
			var sqlResult = await DbContext.ScheduleDateMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == id);

			var topicList = DbContext.ScheduleTopicMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ScheduleId == sqlResult.ScheduleId &&
						x.ScheduleDate == sqlResult.ScheduleDate)
					.Select(x => x.TopicId).ToList();

			var result = new ConferenceScheduleDateModel()
			{
				Id = sqlResult.ID,
				ScheduleId = sqlResult.ScheduleId,
				ScheduleDate = sqlResult.ScheduleDate,
				ForenoonStartTime = sqlResult.ForenoonStartTime,
				ForenoonEndTime = sqlResult.ForenoonEndTime,
				AfternoonStartTime = sqlResult.AfternoonStartTime,
				AfternoonEndTime = sqlResult.AfternoonEndTime,
				EveningStartTime = sqlResult.EveningStartTime,
				EveningEndTime = sqlResult.EveningEndTime,
				TopicId = topicList.Count > 0 ? topicList.ToArray() : null,
				Remark = sqlResult.Remark
			};

			if (result != null)
			{
				return JsonCamelCase(Utility.CreateSuccessJsonResult(string.Empty, result),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("CreateDateReport/{ConferenceId}")]
		public async Task<JsonResult> CreateDateReport(ConferenceScheduleDateModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ScheduleDateMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ScheduleId == model.ScheduleId &&
						x.ScheduleDate == model.ScheduleDate);
			if (result != null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(
						string.Format(Resources.MsgRecordExist, Resources.ScheduleDate)),
						JsonRequestBehavior.AllowGet);
			}

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				var scheduleDateMaster = new ScheduleDateMaster
				{
					ID = Utility.GetTableId(ConstValues.TableName.ScheduleDateMaster),
					ScheduleId = model.ScheduleId,
					ScheduleDate = model.ScheduleDate,
					ForenoonStartTime = model.ForenoonStartTime,
					ForenoonEndTime = model.ForenoonEndTime,
					AfternoonStartTime = model.AfternoonStartTime,
					AfternoonEndTime = model.AfternoonEndTime,
					EveningStartTime = model.EveningStartTime,
					EveningEndTime = model.EveningEndTime,
					Status = ConstValues.Status.正常,
					Sort = ConstValues.DefaultSort,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = DateTime.Now
				};
				DbContext.ScheduleDateMaster.Add(scheduleDateMaster);

				foreach (var topicId in model.TopicId)
				{
					if (!string.IsNullOrEmpty(topicId))
					{
						var scheduleTopicMaster = new ScheduleTopicMaster
						{
							ID = Utility.GetTableId(ConstValues.TableName.ScheduleTopicMaster),
							ScheduleId = model.ScheduleId,
							ScheduleDate = model.ScheduleDate,
							TopicId = topicId,
							Status = ConstValues.Status.正常,
							Sort = ConstValues.DefaultSort,
							Remark = model.Remark?.Trim(),
							Creator = LoginUser.UserName,
							CreateIP = LoginUser.IP,
							CreateDate = DateTime.Now
						};
						DbContext.ScheduleTopicMaster.Add(scheduleTopicMaster);
					}
				}

				await DbContext.SaveChangesAsync();
				transaction.Commit();
			}

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
					JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("ModifyDateReport/{ConferenceId}")]
		public async Task<JsonResult> ModifyDateReport(ConferenceScheduleDateModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var exist = await DbContext.ScheduleDateMaster
					.FirstOrDefaultAsync(x => x.ID != model.Id &&
						x.ScheduleId == model.ScheduleId &&
						x.ScheduleDate == model.ScheduleDate);

			if (exist != null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(
						string.Format(Resources.MsgRecordExist, Resources.ScheduleDate)),
						JsonRequestBehavior.AllowGet);
			}

			var result = await DbContext.ScheduleDateMaster.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				using (var transaction = DbContext.Database.BeginTransaction())
				{
					result.ScheduleId = model.ScheduleId;
					result.ScheduleDate = model.ScheduleDate;
					result.ForenoonStartTime = model.ForenoonStartTime;
					result.ForenoonEndTime = model.ForenoonEndTime;
					result.AfternoonStartTime = model.AfternoonStartTime;
					result.AfternoonEndTime = model.AfternoonEndTime;
					result.EveningStartTime = model.EveningStartTime;
					result.EveningEndTime = model.EveningEndTime;
					result.Status = ConstValues.Status.正常;
					result.Sort = ConstValues.DefaultSort;
					result.Remark = model.Remark?.Trim();
					result.Updater = LoginUser.UserName;
					result.UpdateIP = LoginUser.IP;
					result.UpdateDate = DateTime.Now;

					if (!this.CheckSchedule(result))
					{
						return JsonCamelCase(Utility.CreateFailJsonResult(Resources.ScheduleNotExistＭessage),
								JsonRequestBehavior.AllowGet);
					}

					var viewScheduleContribute = DbContext.ViewScheduleContribute.AsNoTracking()
							.Where(x => x.ScheduleId == model.ScheduleId &&
								x.ScheduleDate == model.ScheduleDate &&
								!string.IsNullOrEmpty(x.TopicId))
							.GroupBy(x => x.TopicId)
							.Select(x => x.Key)
							.ToList();

					foreach (var schedule in viewScheduleContribute)
					{
						// 已安排的日程的报告类型验证
						if (!model.TopicId.Contains(schedule))
						{
							var tempSchedule = DbContext.ViewScheduleContribute.AsNoTracking().FirstOrDefault(x => x.ScheduleId == model.ScheduleId &&
										x.ScheduleDate == model.ScheduleDate &&
										x.TopicId == schedule &&
										x.Status == ConstValues.ScheduleStatus.已安排);
							if(tempSchedule != null)
							{
								return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgCanNotDeleteTopic),
									JsonRequestBehavior.AllowGet);
							}
						}
					}

					var scheduleTopicMasterList = await DbContext.ScheduleTopicMaster
							.Where(x => x.ScheduleId == model.ScheduleId &&
								x.ScheduleDate == model.ScheduleDate).ToListAsync();
					DbContext.ScheduleTopicMaster.RemoveRange(scheduleTopicMasterList);

					foreach (var topicId in model.TopicId)
					{
						if (!string.IsNullOrEmpty(topicId))
						{
							var scheduleTopicMaster = new ScheduleTopicMaster
							{
								ID = Utility.GetTableId(ConstValues.TableName.ScheduleTopicMaster),
								ScheduleId = model.ScheduleId,
								ScheduleDate = model.ScheduleDate,
								TopicId = topicId,
								Status = ConstValues.Status.正常,
								Sort = ConstValues.DefaultSort,
								Remark = model.Remark?.Trim(),
								Creator = LoginUser.UserName,
								CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};
							DbContext.ScheduleTopicMaster.Add(scheduleTopicMaster);
						}
					}

					var scheduleInfoList = await DbContext.ScheduleInfo
							.Where(x => x.ScheduleId == model.ScheduleId &&
								x.ScheduleDate == model.ScheduleDate)
							.OrderBy(x => x.StartTime)
							.ThenBy(x => x.EndTime)
							.ThenBy(x => x.UpdateDate)
							.ThenBy(x => x.ContributeId)
							.ToListAsync();

					TimeSpan todayStartTime ;
					if(model.ForenoonStartTime.HasValue)
					{
						todayStartTime = model.ForenoonStartTime.Value;
					}else if (model.AfternoonStartTime.HasValue)
					{
						todayStartTime = model.AfternoonStartTime.Value;
					}else 
					{
						todayStartTime = model.EveningStartTime.Value;
					}

					if(scheduleInfoList.Count > 0)
					{
						for (var index = 0; index < scheduleInfoList.Count; index++)
						{
							if (!string.IsNullOrEmpty(this.CheckScheduleInfo(scheduleInfoList[index])))
							{
								break;
							}

							if (index == 0)
							{
								// 首条开始时间为当天的开始时间
								this._startTime = todayStartTime;
							}
							else
							{
								// 其余为上一条的结束时间
								this._startTime = this._startTime.Add(TimeSpan.FromMinutes(scheduleInfoList[index - 1].Duration));
							}

							//判断是否跨时区
							if (!this.CheckMoveStartTime(result, scheduleInfoList[index].Duration))
							{
								if (!this.CheckStartTimeForReset(result, scheduleInfoList, scheduleInfoList[index]))
								{
									var hour = scheduleInfoList[index].EndTime.Hours.ToString().Length == 1 ?
											"0" + scheduleInfoList[index].EndTime.Hours.ToString() :
											scheduleInfoList[index].EndTime.Hours.ToString();
									var minute = scheduleInfoList[index].EndTime.Minutes.ToString().Length == 1 ?
											"0" + scheduleInfoList[index].EndTime.Minutes.ToString() :
												scheduleInfoList[index].EndTime.Minutes.ToString();

									return JsonCamelCase(Utility.CreateFailJsonResult(
										string.Format(Resources.MsgHasReport, hour + ":" + minute)),
											JsonRequestBehavior.AllowGet);
								}
								if (!this.CheckMoveStartTime(result, scheduleInfoList[index].Duration))
								{
									var hour = scheduleInfoList[index].EndTime.Hours.ToString().Length == 1 ?
											"0" + scheduleInfoList[index].EndTime.Hours.ToString() :
											scheduleInfoList[index].EndTime.Hours.ToString();
									var minute = scheduleInfoList[index].EndTime.Minutes.ToString().Length == 1 ?
											"0" + scheduleInfoList[index].EndTime.Minutes.ToString() :
												scheduleInfoList[index].EndTime.Minutes.ToString();

									return JsonCamelCase(Utility.CreateFailJsonResult(
										string.Format(Resources.MsgHasReport, hour + ":" + minute)),
											JsonRequestBehavior.AllowGet);
								}
							}

							scheduleInfoList[index].StartTime = this._startTime;
							scheduleInfoList[index].EndTime = this._startTime.Add(TimeSpan.FromMinutes(scheduleInfoList[index].Duration));
							scheduleInfoList[index].Updater = LoginUser.UserName;
							scheduleInfoList[index].UpdateIP = LoginUser.IP;
							scheduleInfoList[index].UpdateDate = DateTime.Now.AddSeconds(index);
						}
					}

					await DbContext.SaveChangesAsync();
					transaction.Commit();
				}

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("DeleteDateReport/{ConferenceId}")]
		public async Task<JsonResult> DeleteDateReport(ConferenceScheduleDateModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ScheduleDateMaster
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			var exist = await DbContext.ScheduleInfo.AsNoTracking()
					.Where(x => x.ScheduleId == result.ScheduleId &&
						x.ScheduleDate == result.ScheduleDate).ToListAsync();

			if (exist.Count > 0)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgUsingCanNotDelete),
						JsonRequestBehavior.AllowGet);
			}

			if (result != null)
			{
				using (var transaction = DbContext.Database.BeginTransaction())
				{
					DbContext.ScheduleDateMaster.Remove(result);

					var scheduleTopicMasterList = await DbContext.ScheduleTopicMaster
							.Where(x => x.ScheduleId == result.ScheduleId &&
								x.ScheduleDate == result.ScheduleDate).ToListAsync();
					DbContext.ScheduleTopicMaster.RemoveRange(scheduleTopicMasterList);

					await DbContext.SaveChangesAsync();
					transaction.Commit();
				}

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessDelete),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		public async Task<JsonCamelCaseResult> GetTopicChairmanData(string conferenceId, string scheduleId)
		{
			var sql = from scheduleMaster in DbContext.ScheduleMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ConferenceId == conferenceId &&
						x.ID == scheduleId)
				  join scheduleTopicMaster in DbContext.ScheduleTopicMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常)
				  on scheduleMaster.ID equals scheduleTopicMaster.ScheduleId
				  join topicMaster in DbContext.TopicMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常)
				  on scheduleTopicMaster.TopicId equals topicMaster.ID
				  orderby topicMaster.TopicName
				  select new
				  {
					  SchedulePlace = scheduleMaster.SchedulePlace,
					  TopicId = scheduleTopicMaster.TopicId,
					  TopicName = topicMaster.TopicName,
				  };

			var result = await sql.ToListAsync();

			return JsonCamelCase(new
			{
				Rows = result.Distinct(),
			},
			JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetAllChairmanData(ConferenceScheduleEventModel model)
		{
			var conferenceMaster = DbContext.ConferenceMaster.AsNoTracking().FirstOrDefault(x => x.ID == model.ConferenceId);

			var sqlResult = await DbContext.ScheduleEventMaster.AsNoTracking()
					.Where(x => x.ConferenceId == model.ConferenceId &&
						x.TopicId == model.TopicId &&
						!string.IsNullOrEmpty(x.Chairman) &&
						x.Status == ConstValues.Status.正常)
					.ToListAsync();

			var result = new List<ConferenceScheduleReportModel>();
			sqlResult.ForEach(y =>
			{
				if (!result.Exists(x => x.FullName == y.Chairman && x.Mail == y.ChairmanMail && x.ContributeId == y.ContributeId))
				{
					var affiliationList = DbContext.AffiliationInfo.AsNoTracking()
						.Where(x => x.Status == ConstValues.Status.正常 &&
							x.ConferenceId == y.ConferenceId &&
							x.ContributeId == y.ContributeId &&
							x.Mail == y.ChairmanMail)
						.OrderBy(x => x.Sort)
						.ThenBy(x => x.Affiliation)
						.Select(x => new
						{
							Affiliation = x.Affiliation,
							Country = x.Country
						})
						.Distinct()
						.ToList();

					var affiliation = string.Empty;
					if(affiliationList.Count > 0)
					{
						foreach(var x in affiliationList)
						{
							if(!string.IsNullOrEmpty(affiliation))
							{
								affiliation += ConstValues.strSemicolon;
							}
							affiliation += x.Affiliation;
							if (conferenceMaster.IsInternational)
							{
								affiliation += ConstValues.strComma + DbContext.LocationMaster.AsNoTracking().FirstOrDefault(z => z.ID == x.Country)?.NameEn;
							}
						}						
					}

					result.Add(new ConferenceScheduleReportModel()
					{
						Id = y.ID,
						FullName = y.Chairman,
						Mail = y.ChairmanMail,
						Affiliation = affiliation,
						ScheduleStatus = y.ScheduleStatus,
						ContributeId = y.ContributeId,
					});
				}
			});

			return JsonCamelCase(new
			{
				Rows = result,
			},
			JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetChairmanData(ConferenceScheduleEventModel model)
		{
			var conferenceMaster = DbContext.ConferenceMaster.AsNoTracking().FirstOrDefault(x => x.ID == model.ConferenceId);

			var sql = from conferenceContributeInfo in DbContext.ConferenceContributeInfo.AsNoTracking()
					.Where(x => x.IsConfirm &&
						x.ConferenceId == model.ConferenceId &&
						(!string.IsNullOrEmpty(x.AdminStatus) ? x.AdminStatus == ConstValues.ContributationStatus.录用 :
							x.ContributationStatus == ConstValues.ContributationStatus.录用))
				  join author in DbContext.AuthorInfo.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
				  on conferenceContributeInfo.ID equals author.ContributeId
				  orderby author.FullName
				  select new
				  {
					  Id = author.ID,
					  ConferenceId = author.ConferenceId,
					  ContributeId = author.ContributeId,
					  TopicId = conferenceContributeInfo.TopicId,
					  FullName = author.FullName,
					  Mail = author.Mail,
				  };

			if (!string.IsNullOrWhiteSpace(model.SelMail))
			{
				sql = sql.Where(x => x.Mail.Contains(model.SelMail));
			}
			if (!string.IsNullOrWhiteSpace(model.SelAuthorName))
			{
				sql = sql.Where(x => x.FullName.Contains(model.SelAuthorName));
			}

			var sqlResult = await sql.ToListAsync();

			var result = new List<ConferenceScheduleReportModel>();
			sqlResult.ForEach(y =>
			{
				if (!result.Exists(x => x.FullName == y.FullName && x.Mail == y.Mail && x.ContributeId == y.ContributeId))
				{
					var affiliationList = DbContext.AffiliationInfo.AsNoTracking()
						.Where(x => x.Status == ConstValues.Status.正常 &&
							x.ConferenceId == y.ConferenceId &&
							x.ContributeId == y.ContributeId &&
							x.Mail == y.Mail)
						.OrderBy(x => x.Sort)
						.ThenBy(x => x.Affiliation)
						.Select(x => new
						{
							Affiliation = x.Affiliation,
							Country = x.Country
						})
						.Distinct()
						.ToList();

					var affiliation = string.Empty;
					if (affiliationList.Count > 0)
					{
						foreach (var x in affiliationList)
						{
							if (!string.IsNullOrEmpty(affiliation))
							{
								affiliation += ConstValues.strSemicolon;
							}
							affiliation += x.Affiliation;
							if (conferenceMaster.IsInternational)
							{
								affiliation += ConstValues.strComma + DbContext.LocationMaster.AsNoTracking().FirstOrDefault(z => z.ID == x.Country)?.NameEn;
							}
						}
					}

					var strFlag = DbContext.ScheduleEventMaster.AsNoTracking()
						.FirstOrDefault(x => x.Status == ConstValues.Status.正常 &&
							x.ConferenceId == y.ConferenceId &&
							x.TopicId == model.TopicId &&
							x.Chairman == y.FullName &&
							x.ChairmanMail == y.Mail)?.ID;

					result.Add(new ConferenceScheduleReportModel()
					{
						Id = y.Id,
						FullName = y.FullName,
						Mail = y.Mail,
						Affiliation = affiliation,
						Flag = strFlag,
						ContributeId = y.ContributeId,
					});
				}
			});

			return JsonCamelCase(new
			{
				Rows = result,
			},
			JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("UpdateChairman/{ConferenceId}")]
		public async Task<JsonResult> UpdateChairman(ConferenceScheduleEventModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				var chairmanList = model.Chairman.Split(ConstValues.chrComma);
				foreach (var chairman in chairmanList)
				{
					var author = DbContext.AuthorInfo.AsNoTracking().FirstOrDefault(x => x.ID == chairman);

					var result = await DbContext.ScheduleEventMaster.AsNoTracking()
							.FirstOrDefaultAsync(x => x.ConferenceId == model.ConferenceId &&
								x.TopicId == model.TopicId &&
								x.Chairman == author.FullName &&
								x.ChairmanMail == author.Mail &&
								x.ContributeId == author.ContributeId);

					if (result == null)
					{
						var scheduleEventMaster = new ScheduleEventMaster
						{
							ID = Utility.GetTableId(ConstValues.TableName.ScheduleEventMaster),
							ConferenceId = model.ConferenceId,
							EventName = Resources.Chairman + ConstValues.chrColon + ConstValues.strSpace + author.FullName,
							Duration = ConstValues.intZero,
							TopicId = model.TopicId,
							Chairman = author.FullName,
							ChairmanMail = author.Mail,
							ContributeId = author.ContributeId,
							ScheduleStatus = ConstValues.ScheduleStatus.待安排,
							Status = ConstValues.Status.正常,
							Sort = ConstValues.DefaultSort,
							Remark = model.Remark?.Trim(),
							Creator = LoginUser.UserName,
							CreateIP = LoginUser.IP,
							CreateDate = DateTime.Now
						};
						DbContext.ScheduleEventMaster.Add(scheduleEventMaster);
					}
				}

				await DbContext.SaveChangesAsync();
				transaction.Commit();
			}

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
					JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetPlanData(string scheduleDateId)
		{
			var scheduleDateMaster = await DbContext.ScheduleDateMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == scheduleDateId);
			
			var scheduleMaster = await DbContext.ScheduleMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == scheduleDateMaster.ScheduleId);

			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == scheduleMaster.ConferenceId);

			var sql = from scheduleInfo in DbContext.ScheduleInfo.AsNoTracking()
						.Where(x => x.ScheduleId == scheduleDateMaster.ScheduleId && x.ScheduleDate == scheduleDateMaster.ScheduleDate)
				  join conferenceContributeInfo in DbContext.ConferenceContributeInfo.AsNoTracking()
					  on scheduleInfo.ContributeId equals conferenceContributeInfo.ID into t1
				  from contribute in t1.DefaultIfEmpty()
				  join authorInfo in DbContext.AuthorInfo.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常 && x.IsPresenter)
					  on contribute.ID equals authorInfo.ContributeId into t2
				  from author in t2.DefaultIfEmpty()
				  join reportMaster in DbContext.ReportMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					  on contribute.ReportId equals reportMaster.ID into t3
				  from report in t3.DefaultIfEmpty()
				  join topicMaster in DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					  on contribute.TopicId equals topicMaster.ID into t4
				  from topic in t4.DefaultIfEmpty()
				  join scheduleEventMaster in DbContext.ScheduleEventMaster.AsNoTracking()
					  on scheduleInfo.ContributeId equals scheduleEventMaster.ID into t5
				  from scheduleEvent in t5.DefaultIfEmpty()
				  join topicMaster in DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					  on scheduleEvent.TopicId equals topicMaster.ID into t6
				  from topic2 in t6.DefaultIfEmpty()
				  orderby scheduleInfo.StartTime, scheduleInfo.EndTime, scheduleInfo.UpdateDate, scheduleInfo.ContributeId
				  select new
				  {
					  Flag = scheduleInfo.EndTime <= scheduleDateMaster.ForenoonEndTime ? Resources.Forenoon :
						  scheduleInfo.EndTime <= scheduleDateMaster.AfternoonEndTime ? Resources.Afternoon :
						  Resources.Evening,
					  Id = scheduleInfo.ID,
					  ReportType = scheduleInfo.IsContribute ? report.ReportType : (string.IsNullOrEmpty(scheduleEvent.Chairman) ? Resources.ScheduleEvent : Resources.Chairman),
					  TopicName = scheduleInfo.IsContribute ? topic.TopicName : topic2.TopicName,
					  ContributeId = scheduleInfo.IsContribute ? contribute.ID : scheduleEvent.ID,
					  EssayTitle = scheduleInfo.IsContribute ? contribute.EssayTitle : scheduleEvent.EventName,
					  FullName = author.FullName,
					  //Affiliation = author.Affiliation,
					  Mail = author.Mail,
					  StartTime = scheduleInfo.StartTime.ToString().Substring(0, 5),
					  EndTime = scheduleInfo.EndTime.ToString().Substring(0, 5),
					  Duration = scheduleInfo.Duration,
					  IsContribute = scheduleInfo.IsContribute,
					  IsLock = scheduleInfo.IsLock,
					  Status = scheduleInfo.Status,
					  Remark = scheduleInfo.IsContribute ? contribute.Remark : scheduleEvent.Remark,
					  ConferenceId = contribute.ConferenceId
				  };

			var sqlResult = await sql.ToListAsync();

			var result = new List<ConferenceScheduleReportModel>();
			sqlResult.ForEach(y =>
			{
				var affiliationList = DbContext.AffiliationInfo.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ConferenceId == y.ConferenceId &&
						x.ContributeId == y.ContributeId &&
						x.Mail == y.Mail)
					.OrderBy(x => x.Sort)
					.ThenBy(x => x.Affiliation)
					.Select(x => new
					{
						Affiliation = x.Affiliation,
						Country = x.Country
					})
					.Distinct()
					.ToList();
				var affiliation = string.Empty;
				if (affiliationList.Count > 0)
				{
					foreach (var x in affiliationList)
					{
						if (!string.IsNullOrEmpty(affiliation))
						{
							affiliation += ConstValues.strSemicolon;
						}
						affiliation += x.Affiliation;
						if (conferenceMaster.IsInternational)
						{
							affiliation += ConstValues.strComma + DbContext.LocationMaster.AsNoTracking().FirstOrDefault(z => z.ID == x.Country)?.NameEn;
						}
					}
				}

				var authorList = DbContext.AuthorInfo.AsNoTracking()
					.Where(x => x.ContributeId == y.Id &&
						x.ConferenceId == y.ConferenceId)
					.OrderBy(x => x.Sort)
					.Select(x => x.FullName);

				result.Add(new ConferenceScheduleReportModel()
				{
					Flag = y.Flag,
					Id = y.Id,
					ReportType = y.ReportType,
					TopicName = y.TopicName,
					ContributeId = y.IsContribute ? y.ContributeId : string.Empty,
					EssayTitle = y.IsContribute ? y.EssayTitle : Utility.GetScheduleEventNameById(y.ContributeId),
					FullName = y.FullName,
					Affiliation = affiliation,
					Author = string.Join(ConstValues.strSemicolon, authorList),
					StartTime = y.StartTime,
					EndTime = y.EndTime,
					Duration = y.Duration,
					IsContribute = y.IsContribute,
					IsLock = y.IsLock,
					Status = y.Status,
					Remark = y.Remark
				});
			});

			return JsonCamelCase(new
			{
				Rows = result,
			},
			JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetWaitData(string conferenceId, string scheduleDateId, string reportTypeId,string topicId)
		{
			var conferenceMaster = DbContext.ConferenceMaster.AsNoTracking().FirstOrDefault(x => x.ID == conferenceId);

			var scheduleDateMaster = await DbContext.ScheduleDateMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == scheduleDateId);

			var topicList = DbContext.ScheduleTopicMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ScheduleId == scheduleDateMaster.ScheduleId &&
						x.ScheduleDate == scheduleDateMaster.ScheduleDate)
					.Select(x => x.TopicId).ToList();

			var sql = from contribute in DbContext.ConferenceContributeInfo.AsNoTracking()
						.Where(x => x.IsConfirm &&
							x.ConferenceId == conferenceId &&
							x.ScheduleStatus == ConstValues.ScheduleStatus.待安排 &&
							(!string.IsNullOrEmpty(x.AdminStatus) ? x.AdminStatus == ConstValues.ContributationStatus.录用 :
								x.ContributationStatus == ConstValues.ContributationStatus.录用))
				  join reportMaster in DbContext.ReportMaster.AsNoTracking()
					  .Where(x => x.Status == ConstValues.Status.正常 && x.ReportType != ConstValues.PosterCn && x.ReportType != ConstValues.PosterEn)
					  on contribute.ReportId equals reportMaster.ID
				  join topicMaster in DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常 && topicList.Contains(x.ID))
					  on contribute.TopicId equals topicMaster.ID
				  join authorInfo in DbContext.AuthorInfo.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常 && x.IsPresenter)
					  on contribute.ID equals authorInfo.ContributeId into t3
				  from author in t3.DefaultIfEmpty()
				  orderby reportMaster.ReportType, topicMaster.TopicName, contribute.EssayTitle
				  select new
				  {
					  ReportTypeId = reportMaster.ID,
					  ReportType = reportMaster.ReportType,
					  TopicId = topicMaster.ID,
					  TopicName = topicMaster.TopicName,
					  Id = contribute.ID,
					  EssayTitle = contribute.EssayTitle,
					  FullName = author.FullName,
					  Mail = author.Mail,
					  Duration = reportMaster.Duration,
					  Remark = contribute.Remark,
					  ConferenceId = contribute.ConferenceId,
					  ContributeId = contribute.ID
				  };
			if (!string.IsNullOrEmpty(reportTypeId))
			{
				sql = sql.Where(x => x.ReportTypeId == reportTypeId);
			}

			if (!string.IsNullOrEmpty(topicId))
			{
				sql = sql.Where(x => x.TopicId == topicId);
			}

			var sqlResult = await sql.ToListAsync();

			var result = new List<ConferenceScheduleReportModel>();
			sqlResult.ForEach(y =>
			{
				var affiliationList = DbContext.AffiliationInfo.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ConferenceId == y.ConferenceId &&
						x.ContributeId == y.ContributeId &&
						x.Mail == y.Mail)
					.OrderBy(x => x.Sort)
					.ThenBy(x => x.Affiliation)
					.Select(x => new
					{
						Affiliation = x.Affiliation,
						Country = x.Country
					})
					.Distinct()
					.ToList();
				var affiliation = string.Empty;
				if (affiliationList.Count > 0)
				{
					foreach (var x in affiliationList)
					{
						if (!string.IsNullOrEmpty(affiliation))
						{
							affiliation += ConstValues.strSemicolon;
						}
						affiliation += x.Affiliation;
						if (conferenceMaster.IsInternational)
						{
							affiliation += ConstValues.strComma + DbContext.LocationMaster.AsNoTracking().FirstOrDefault(z => z.ID == x.Country)?.NameEn;
						}
					}

				}

				var authorList = DbContext.AuthorInfo.AsNoTracking()
					.Where(x => x.ContributeId == y.ContributeId &&
						x.ConferenceId == y.ConferenceId)
					.OrderBy(x => x.Sort)
					.Select(x => x.FullName);

				result.Add(new ConferenceScheduleReportModel()
				{
					ReportType = y.ReportType,
					TopicName = y.TopicName,
					Id = y.Id,
					EssayTitle = y.EssayTitle,
					FullName = y.FullName,
					Affiliation = affiliation,
					Author = string.Join(ConstValues.strSemicolon, authorList),
					Duration = y.Duration,
					Remark = y.Remark
				});
			});

			return JsonCamelCase(new
			{
				Rows = result,
			},
			JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetEventData(string conferenceId, string scheduleDateId)
		{
			var scheduleDateMaster = await DbContext.ScheduleDateMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == scheduleDateId);

			var topicList = DbContext.ScheduleTopicMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ScheduleId == scheduleDateMaster.ScheduleId &&
						x.ScheduleDate == scheduleDateMaster.ScheduleDate)
					.Select(x => x.TopicId).ToList();

			var result = await DbContext.ScheduleEventMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ScheduleStatus == ConstValues.ScheduleStatus.待安排 &&
						x.ConferenceId == conferenceId &&
						(topicList.Contains(x.TopicId) || string.IsNullOrEmpty(x.TopicId)))
					.GroupJoin(DbContext.TopicMaster.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId),
						scheduleEvent => scheduleEvent.TopicId,
						topicMaster => topicMaster.ID,
						(scheduleEvent, topicMaster) => new
						{
							ID = scheduleEvent.ID,
							EventName = scheduleEvent.EventName,
							Duration = scheduleEvent.Duration,
							TopicId = scheduleEvent.TopicId,
							TopicName = topicMaster.FirstOrDefault().TopicName,
							Sort = scheduleEvent.Sort,
							Remark = scheduleEvent.Remark,
							ChairmanMail = scheduleEvent.ChairmanMail,
						})
					.OrderBy(x => x.Sort)
					.ThenBy(x => x.TopicName)
					.ThenBy(x => x.EventName)
					.ToListAsync();



			var newResult = result.Select(x => new
			{
				ID = x.ID,
				EventName = string.IsNullOrEmpty(x.ChairmanMail) ? x.EventName :
					Utility.GetScheduleEventNameById(x.ID),
				Duration = x.Duration,
				TopicId = x.TopicId,
				TopicName = x.TopicName,
				Sort = x.Sort,
				Remark = x.Remark,
			});

			return JsonCamelCase(new
			{
				Rows = newResult,
			},
			JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("SchedulePlan/{ConferenceId}")]
		public async Task<JsonResult> SchedulePlan(ConferenceScheduleInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var scheduleDateMaster = await DbContext.ScheduleDateMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == model.ScheduleDateId);

			if (!this.CheckSchedule(scheduleDateMaster))
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.ScheduleNotExistＭessage),
						JsonRequestBehavior.AllowGet);
			}

			var scheduleInfoList = await DbContext.ScheduleInfo.AsNoTracking()
					.Where(x => x.ScheduleId == scheduleDateMaster.ScheduleId &&
						x.ScheduleDate == scheduleDateMaster.ScheduleDate)
					.OrderBy(x => x.StartTime)
					.ToListAsync();

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				if (scheduleInfoList.Count == 0 || model.Duration == 0)
				{
					#region 当天没有安排过日程
					if (this._durationForenoon > model.Duration)
					{
						// 上午时间区间足够，安排在上午
						this._startTime = scheduleDateMaster.ForenoonStartTime.Value;
					}
					else if (this._durationAfternoon > model.Duration)
					{
						// 下午时间区间足够，安排在下午
						this._startTime = scheduleDateMaster.AfternoonStartTime.Value;
					}
					else if (this._durationEvening > model.Duration)
					{
						// 晚上时间区间足够，安排在晚上
						this._startTime = scheduleDateMaster.EveningStartTime.Value;
					}
					else
					{
						return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
								JsonRequestBehavior.AllowGet);
					}
					#endregion
				}
				else
				{
					#region 当天安排过日程
					if (!this.CheckStartTime(scheduleDateMaster, scheduleInfoList, new ScheduleInfo() { Duration = model.Duration }))
					{
						return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
								JsonRequestBehavior.AllowGet);
					}
					#endregion
				}

				#region 插入日程信息表
				var scheduleInfo = new ScheduleInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.ScheduleInfo),
					ScheduleId = scheduleDateMaster.ScheduleId,
					ScheduleDate = scheduleDateMaster.ScheduleDate,
					IsContribute = model.IsContribute,
					ContributeId = model.ContributeId,
					StartTime = this._startTime,
					EndTime = this._startTime.Add(TimeSpan.FromMinutes(model.Duration)),
					Duration = model.Duration,
					IsLock = false,
					Status = ConstValues.ScheduleStatus.已安排,
					Sort = ConstValues.DefaultSort,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = DateTime.Now
				};
				DbContext.ScheduleInfo.Add(scheduleInfo);
				#endregion

				// 更新参会投稿信息表/日程环节管理表
				this.UpdateContributeOrEvent(model.IsContribute, model.ContributeId, ConstValues.ScheduleStatus.已安排);

				await DbContext.SaveChangesAsync();
				transaction.Commit();
			}

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
					JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("LockSchedulePlan/{ConferenceId}")]
		public async Task<JsonResult> LockSchedulePlan(ConferenceScheduleInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ScheduleInfo
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				result.IsLock = model.IsLock;
				result.Updater = LoginUser.UserName;
				result.UpdateIP = LoginUser.IP;
				result.UpdateDate = DateTime.Now;
				await DbContext.SaveChangesAsync();

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("RecoverSchedulePlan/{ConferenceId}")]
		public async Task<JsonResult> RecoverSchedulePlan(ConferenceScheduleInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ScheduleInfo
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				using (var transaction = DbContext.Database.BeginTransaction())
				{
					var scheduleStatus = model.ScheduleStatus == ConstValues.ScheduleStatus.已取消 ?
							ConstValues.ScheduleStatus.已安排 : ConstValues.ScheduleStatus.已取消;
					model.ScheduleStatus = scheduleStatus;

					result.Status = model.ScheduleStatus;
					result.Updater = LoginUser.UserName;
					result.UpdateIP = LoginUser.IP;
					result.UpdateDate = DateTime.Now;

					// 更新参会投稿信息表/日程环节管理表
					this.UpdateContributeOrEvent(result.IsContribute, result.ContributeId, scheduleStatus);

					await DbContext.SaveChangesAsync();
					transaction.Commit();
				}

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("CancelSchedulePlan/{ConferenceId}")]
		public async Task<JsonResult> CancelSchedulePlan(ConferenceScheduleInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ScheduleInfo
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				var scheduleDateMaster = await DbContext.ScheduleDateMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == model.ScheduleDateId);

				if (!this.CheckSchedule(scheduleDateMaster))
				{
					return JsonCamelCase(Utility.CreateFailJsonResult(Resources.ScheduleNotExistＭessage),
							JsonRequestBehavior.AllowGet);
				}

				using (var transaction = DbContext.Database.BeginTransaction())
				{
					// 更新参会投稿信息表/日程环节管理表
					this.UpdateContributeOrEvent(result.IsContribute, result.ContributeId, ConstValues.ScheduleStatus.待安排);

					#region 后续安排上移
					var scheduleInfoList = await DbContext.ScheduleInfo
							.Where(x => x.ScheduleId == scheduleDateMaster.ScheduleId &&
								x.ScheduleDate == scheduleDateMaster.ScheduleDate)
							.OrderBy(x => x.StartTime)
							.ToListAsync();

					var resultIndex = scheduleInfoList.FindIndex(x => x.ID == model.Id);

					// 锁定或已取消之前的安排时间清空
					for (var index = resultIndex + 1; index < scheduleInfoList.Count; index++)
					{
						if (!string.IsNullOrEmpty(this.CheckScheduleInfo(scheduleInfoList[index])))
						{
							break;
						}
						scheduleInfoList[index].StartTime = new TimeSpan(0);
						scheduleInfoList[index].EndTime = new TimeSpan(0);
					}

					// 锁定或已取消之前的安排时间重排
					for (var index = resultIndex + 1; index < scheduleInfoList.Count; index++)
					{
						if (!string.IsNullOrEmpty(this.CheckScheduleInfo(scheduleInfoList[index])))
						{
							break;
						}

						// 首条开始时间为取消安排的开始时间，其余为上一条的结束时间
						this._startTime = index == resultIndex + 1 ? result.StartTime :
								this._startTime.Add(TimeSpan.FromMinutes(scheduleInfoList[index - 1].Duration));

						// 如果该时间到本阶段的结束时间不足以上移，则从下一阶段的开始时间为开始时间
						if (!this.CheckMoveStartTime(scheduleDateMaster, scheduleInfoList[index].Duration) &&
							!this.CheckStartTime(scheduleDateMaster, scheduleInfoList, scheduleInfoList[index]))
						{
							break;
						}

						scheduleInfoList[index].StartTime = this._startTime;
						scheduleInfoList[index].EndTime = this._startTime.Add(TimeSpan.FromMinutes(scheduleInfoList[index].Duration));
						scheduleInfoList[index].Updater = LoginUser.UserName;
						scheduleInfoList[index].UpdateIP = LoginUser.IP;
						scheduleInfoList[index].UpdateDate = DateTime.Now;
					}
					#endregion

					DbContext.ScheduleInfo.Remove(result);

					await DbContext.SaveChangesAsync();
					transaction.Commit();
				}

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("MoveSchedulePlan/{ConferenceId}")]
		public async Task<JsonResult> MoveSchedulePlan(ConferenceScheduleInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ScheduleInfo
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				var scheduleDateMaster = await DbContext.ScheduleDateMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == model.ScheduleDateId);

				if (!this.CheckSchedule(scheduleDateMaster))
				{
					return JsonCamelCase(Utility.CreateFailJsonResult(Resources.ScheduleNotExistＭessage),
							JsonRequestBehavior.AllowGet);
				}

				using (var transaction = DbContext.Database.BeginTransaction())
				{
					var scheduleInfoList = await DbContext.ScheduleInfo
							.Where(x => x.ScheduleId == scheduleDateMaster.ScheduleId &&
								x.ScheduleDate == scheduleDateMaster.ScheduleDate)
							.OrderBy(x => x.StartTime)
							.ThenBy(x => x.EndTime)
							.ThenBy(x => x.UpdateDate)
							.ThenBy(x => x.ContributeId)
							.ToListAsync();

					ScheduleInfo upperInfo, lowerInfo;

					var thisIndex = scheduleInfoList.FindIndex(x => x.ID == result.ID);
					if (model.IsUp)
					{
						#region 上移
						upperInfo = scheduleInfoList[thisIndex - 1];
						lowerInfo = result;
						#endregion
					}
					else
					{
						#region 下移
						upperInfo = result;
						lowerInfo = scheduleInfoList[thisIndex + 1];
						#endregion
					}

					var upperIndex = scheduleInfoList.FindIndex(x => x.ID == upperInfo.ID);
					var lowerIndex = scheduleInfoList.FindIndex(x => x.ID == lowerInfo.ID);
					if (upperInfo.Duration == 0 || lowerInfo.Duration == 0)
					{
						this._startTime = upperInfo.StartTime;
					}
					else
					{
						if (!this.CheckStartTime(scheduleDateMaster, scheduleInfoList, lowerInfo, upperInfo))
						{
							return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
									JsonRequestBehavior.AllowGet);
						}
					}

					if (!this.CheckMoveStartTime(scheduleDateMaster, scheduleInfoList[lowerIndex].Duration))
					{
						if (!this.CheckStartTime(scheduleDateMaster, scheduleInfoList, scheduleInfoList[lowerIndex]))
						{
							return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
									JsonRequestBehavior.AllowGet);
						}
						if (!this.CheckMoveStartTime(scheduleDateMaster, scheduleInfoList[lowerIndex].Duration))
						{
							return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
									JsonRequestBehavior.AllowGet);
						}
					}

					// 原下方的安排上移
					scheduleInfoList[lowerIndex].StartTime = this._startTime;
					scheduleInfoList[lowerIndex].EndTime = this._startTime.Add(TimeSpan.FromMinutes(lowerInfo.Duration));
					scheduleInfoList[lowerIndex].Updater = LoginUser.UserName;
					scheduleInfoList[lowerIndex].UpdateIP = LoginUser.IP;
					scheduleInfoList[lowerIndex].UpdateDate = DateTime.Now.AddSeconds(-1);

					// 锁定或已取消之前的安排时间清空
					for (var index = lowerIndex + 1; index < scheduleInfoList.Count; index++)
					{
						if (!string.IsNullOrEmpty(this.CheckScheduleInfo(scheduleInfoList[index])))
						{
							break;
						}
						scheduleInfoList[index].StartTime = new TimeSpan(0);
						scheduleInfoList[index].EndTime = new TimeSpan(0);
					}

					// 锁定或已取消之前的安排时间重排
					for (var index = upperIndex; index < scheduleInfoList.Count; index++)
					{
						if (index == lowerIndex)
						{
							continue;
						}

						if (!string.IsNullOrEmpty(this.CheckScheduleInfo(scheduleInfoList[index])))
						{
							break;
						}

						if (index == upperIndex)
						{
							// 原上方安排的开始时间为原下方安排现在的结束时间
							this._startTime = scheduleInfoList[lowerIndex].EndTime;
						}
						else if (index == lowerIndex + 1)
						{
							// 首条开始时间为原上方安排现在的结束时间
							this._startTime = scheduleInfoList[upperIndex].StartTime.Add(TimeSpan.FromMinutes(scheduleInfoList[upperIndex].Duration));
						}
						else
						{
							// 其余为上一条的结束时间
							this._startTime = this._startTime.Add(TimeSpan.FromMinutes(scheduleInfoList[index - 1].Duration));
						}

						if (!this.CheckMoveStartTime(scheduleDateMaster, scheduleInfoList[index].Duration))
						{
							if (!this.CheckStartTime(scheduleDateMaster, scheduleInfoList, scheduleInfoList[index]))
							{
								return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
										JsonRequestBehavior.AllowGet);
							}
							if (!this.CheckMoveStartTime(scheduleDateMaster, scheduleInfoList[index].Duration))
							{
								return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
										JsonRequestBehavior.AllowGet);
							}
						}

						scheduleInfoList[index].StartTime = this._startTime;
						scheduleInfoList[index].EndTime = this._startTime.Add(TimeSpan.FromMinutes(scheduleInfoList[index].Duration));
						scheduleInfoList[index].Updater = LoginUser.UserName;
						scheduleInfoList[index].UpdateIP = LoginUser.IP;
						scheduleInfoList[index].UpdateDate = DateTime.Now.AddSeconds(index);
					}

					await DbContext.SaveChangesAsync();
					transaction.Commit();
				}

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("DropSchedulePlan/{ConferenceId}")]
		public async Task<JsonResult> DropSchedulePlan(ConferenceScheduleInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ScheduleInfo
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				var scheduleDateMaster = await DbContext.ScheduleDateMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
							x.ID == model.ScheduleDateId);

				if (!this.CheckSchedule(scheduleDateMaster))
				{
					return JsonCamelCase(Utility.CreateFailJsonResult(Resources.ScheduleNotExistＭessage),
							JsonRequestBehavior.AllowGet);
				}

				using (var transaction = DbContext.Database.BeginTransaction())
				{
					var scheduleInfoList = await DbContext.ScheduleInfo
							.Where(x => x.ScheduleId == scheduleDateMaster.ScheduleId &&
								x.ScheduleDate == scheduleDateMaster.ScheduleDate)
							.OrderBy(x => x.StartTime)
							.ThenBy(x => x.EndTime)
							.ThenBy(x => x.UpdateDate)
							.ThenBy(x => x.ContributeId)
							.ToListAsync();

					ScheduleInfo upperInfo, lowerInfo;

					var sourceIndex = scheduleInfoList.FindIndex(x => x.ID == result.ID);
					var targetIndex = scheduleInfoList.FindIndex(x => x.ID == model.TargetId);

					if (sourceIndex > targetIndex)
					{
						#region 上移
						upperInfo = scheduleInfoList.FirstOrDefault(x => x.ID == model.TargetId);
						lowerInfo = result;
						#endregion
					}
					else
					{
						#region 下移
						upperInfo = result;
						lowerInfo = scheduleInfoList.FirstOrDefault(x => x.ID == model.TargetId);
						#endregion
					}

					var upperIndex = scheduleInfoList.FindIndex(x => x.ID == upperInfo.ID);
					var lowerIndex = scheduleInfoList.FindIndex(x => x.ID == lowerInfo.ID);

					// 首条开始时间为原上方安排的开始时间
					this._startTime = upperInfo.StartTime;

					// 除锁定或已取消的安排时间清空
					for (var index = upperIndex; index < scheduleInfoList.Count; index++)
					{
						if (!string.IsNullOrEmpty(this.CheckScheduleInfo(scheduleInfoList[index])))
						{
							continue;
						}
						scheduleInfoList[index].StartTime = new TimeSpan(0);
						scheduleInfoList[index].EndTime = new TimeSpan(0);
					}

					// 除锁定或已取消的安排时间重排
					if (sourceIndex > targetIndex)
					{
						#region 上移
						// 优先处理需要上移的安排
						if (scheduleInfoList[lowerIndex].Duration != 0)
						{
							if (!this.CheckStartTime(scheduleDateMaster, scheduleInfoList, scheduleInfoList[lowerIndex]))
							{
								return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
										JsonRequestBehavior.AllowGet);
							}
							if (!this.CheckMoveStartTime(scheduleDateMaster, scheduleInfoList[lowerIndex].Duration))
							{
								return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
										JsonRequestBehavior.AllowGet);
							}
						}

						scheduleInfoList[lowerIndex].StartTime = this._startTime;
						scheduleInfoList[lowerIndex].EndTime = this._startTime.Add(TimeSpan.FromMinutes(scheduleInfoList[lowerIndex].Duration));
						scheduleInfoList[lowerIndex].Updater = LoginUser.UserName;
						scheduleInfoList[lowerIndex].UpdateIP = LoginUser.IP;
						scheduleInfoList[lowerIndex].UpdateDate = DateTime.Now.AddSeconds(upperIndex);

						this._startTime = scheduleInfoList[lowerIndex].EndTime;

						// 从被迫下移的安排开始处理
						for (var index = upperIndex; index < scheduleInfoList.Count; index++)
						{
							// 跳过需要上移的安排
							if (index == lowerIndex)
							{
								continue;
							}

							// 跳过锁定或已取消的安排
							if (!string.IsNullOrEmpty(this.CheckScheduleInfo(scheduleInfoList[index])))
							{
								continue;
							}

							if (scheduleInfoList[index].Duration != 0)
							{
								if (!this.CheckStartTime(scheduleDateMaster, scheduleInfoList, scheduleInfoList[index]))
								{
									return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
											JsonRequestBehavior.AllowGet);
								}
								if (!this.CheckMoveStartTime(scheduleDateMaster, scheduleInfoList[index].Duration))
								{
									return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
											JsonRequestBehavior.AllowGet);
								}
							}

							scheduleInfoList[index].StartTime = this._startTime;
							scheduleInfoList[index].EndTime = this._startTime.Add(TimeSpan.FromMinutes(scheduleInfoList[index].Duration));
							scheduleInfoList[index].Updater = LoginUser.UserName;
							scheduleInfoList[index].UpdateIP = LoginUser.IP;
							scheduleInfoList[index].UpdateDate = DateTime.Now.AddSeconds(index);

							this._startTime = scheduleInfoList[index].EndTime;
						}
						#endregion
					}
					else
					{
						#region 下移
						var isChange = false;
						// 从需要下移安排的下一条开始处理
						for (var index = upperIndex + 1; index < scheduleInfoList.Count; index++)
						{
							// 插入处理需要下移的安排
							if (index == lowerIndex + 1 && !isChange)
							{
								if (scheduleInfoList[upperIndex].Duration != 0)
								{
									if (!this.CheckStartTime(scheduleDateMaster, scheduleInfoList, scheduleInfoList[upperIndex]))
									{
										return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
												JsonRequestBehavior.AllowGet);
									}
									if (!this.CheckMoveStartTime(scheduleDateMaster, scheduleInfoList[upperIndex].Duration))
									{
										return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
												JsonRequestBehavior.AllowGet);
									}
								}

								scheduleInfoList[upperIndex].StartTime = this._startTime;
								scheduleInfoList[upperIndex].EndTime = this._startTime.Add(TimeSpan.FromMinutes(scheduleInfoList[upperIndex].Duration));
								scheduleInfoList[upperIndex].Updater = LoginUser.UserName;
								scheduleInfoList[upperIndex].UpdateIP = LoginUser.IP;
								scheduleInfoList[upperIndex].UpdateDate = DateTime.Now.AddSeconds(upperIndex);

								this._startTime = scheduleInfoList[upperIndex].EndTime;

								isChange = true;
								index -= 1;
								continue;
							}

							// 跳过锁定或已取消的安排
							if (!string.IsNullOrEmpty(this.CheckScheduleInfo(scheduleInfoList[index])))
							{
								continue;
							}

							if (scheduleInfoList[index].Duration != 0)
							{
								if (!this.CheckStartTime(scheduleDateMaster, scheduleInfoList, scheduleInfoList[index]))
								{
									return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
											JsonRequestBehavior.AllowGet);
								}
								if (!this.CheckMoveStartTime(scheduleDateMaster, scheduleInfoList[index].Duration))
								{
									return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
											JsonRequestBehavior.AllowGet);
								}
							}

							scheduleInfoList[index].StartTime = this._startTime;
							scheduleInfoList[index].EndTime = this._startTime.Add(TimeSpan.FromMinutes(scheduleInfoList[index].Duration));
							scheduleInfoList[index].Updater = LoginUser.UserName;
							scheduleInfoList[index].UpdateIP = LoginUser.IP;
							scheduleInfoList[index].UpdateDate = DateTime.Now.AddSeconds(index);

							this._startTime = scheduleInfoList[index].EndTime;
						}

						// 移动到最后的情况
						if (!isChange)
						{
							if (scheduleInfoList[upperIndex].Duration != 0)
							{
								if (!this.CheckStartTime(scheduleDateMaster, scheduleInfoList, scheduleInfoList[upperIndex]))
								{
									return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
											JsonRequestBehavior.AllowGet);
								}
								if (!this.CheckMoveStartTime(scheduleDateMaster, scheduleInfoList[upperIndex].Duration))
								{
									return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleNotEnough),
											JsonRequestBehavior.AllowGet);
								}
							}

							scheduleInfoList[upperIndex].StartTime = this._startTime;
							scheduleInfoList[upperIndex].EndTime = this._startTime.Add(TimeSpan.FromMinutes(scheduleInfoList[upperIndex].Duration));
							scheduleInfoList[upperIndex].Updater = LoginUser.UserName;
							scheduleInfoList[upperIndex].UpdateIP = LoginUser.IP;
							scheduleInfoList[upperIndex].UpdateDate = DateTime.Now.AddSeconds(upperIndex);
						}
						#endregion
					}

					await DbContext.SaveChangesAsync();
					transaction.Commit();
				}

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<FileResult> Export(string conferenceId)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", conferenceId);
			
			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == conferenceId &&
						x.Status == ConstValues.Status.正常);

			var export = Resources.export_scheduleInfo;

			XSSFWorkbook workbook;

			using (MemoryStream readStream = new MemoryStream(export))
			{
				workbook = new XSSFWorkbook(readStream);

				var scheduleMasterList = await DbContext.ScheduleMaster.AsNoTracking()
						.Where(x => x.ConferenceId == conferenceId &&
							x.Status == ConstValues.Status.正常)
						.OrderBy(x => x.Sort)
						.ThenByDescending(x => x.UpdateDate)
						.ThenBy(x => x.SchedulePlace)
						.ToListAsync();

				foreach (var scheduleMaster in scheduleMasterList)
				{
					var scheduleDateMasterList = DbContext.ScheduleDateMaster.AsNoTracking()
							.Where(x => x.ScheduleId == scheduleMaster.ID &&
								x.Status == ConstValues.Status.正常)
							.OrderBy(x => x.ScheduleDate)
							.ToList();

					ISheet sheetModel = workbook.GetSheetAt(0);
					ISheet newSheet = sheetModel.CopySheet(scheduleMaster.SchedulePlace);
					ICellStyle cellStyle = workbook.CreateCellStyle();
					cellStyle.VerticalAlignment = VerticalAlignment.Center;
					cellStyle.WrapText = true;
					ICellStyle cellStyle2 = workbook.CreateCellStyle();
					cellStyle2.VerticalAlignment = VerticalAlignment.Justify;

					var rowIndex = 0;

					#region 地点区分
					foreach (var scheduleDateMaster in scheduleDateMasterList)
					{
						var columnIndex = 0;
						var topicList = DbContext.ScheduleTopicMaster.AsNoTracking()
								.Where(x => x.Status == ConstValues.Status.正常 &&
									x.ScheduleId == scheduleDateMaster.ScheduleId &&
									x.ScheduleDate == scheduleDateMaster.ScheduleDate)
								.Join(DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常),
									schedule => schedule.TopicId,
									topic => topic.ID,
									(schedule, topic) => new
									{
										TopicName = topic.TopicName
									})
								.OrderBy(x => x.TopicName)
								.Select(x => x.TopicName)
								.ToList();

						#region 日期区分
						var sql = from scheduleInfo in DbContext.ScheduleInfo.AsNoTracking()
								.Where(x => x.ScheduleId == scheduleMaster.ID &&
									x.ScheduleDate == scheduleDateMaster.ScheduleDate)
							  join conferenceContributeInfo in DbContext.ConferenceContributeInfo.AsNoTracking()
								  on scheduleInfo.ContributeId equals conferenceContributeInfo.ID into t1
							  from contribute in t1.DefaultIfEmpty()
							  join authorInfo in DbContext.AuthorInfo.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常 && x.IsPresenter)
								  on contribute.ID equals authorInfo.ContributeId into t2
							  from author in t2.DefaultIfEmpty()
							  join reportMaster in DbContext.ReportMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
								  on contribute.ReportId equals reportMaster.ID into t3
							  from report in t3.DefaultIfEmpty()
							  join topicMaster in DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
								  on contribute.TopicId equals topicMaster.ID into t4
							  from topic in t4.DefaultIfEmpty()
							  join scheduleEventMaster in DbContext.ScheduleEventMaster.AsNoTracking()
								  on scheduleInfo.ContributeId equals scheduleEventMaster.ID into t5
							  from scheduleEvent in t5.DefaultIfEmpty()
							  join topicMaster in DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
								  on scheduleEvent.TopicId equals topicMaster.ID into t6
							  from topic2 in t6.DefaultIfEmpty()
							  orderby scheduleInfo.StartTime, scheduleInfo.EndTime, scheduleInfo.UpdateDate, scheduleInfo.ContributeId
							  select new
							  {
								  Id = scheduleInfo.ID,
								  ReportType = scheduleInfo.IsContribute ? report.ReportType : Resources.ScheduleEvent,
								  TopicName = scheduleInfo.IsContribute ? topic.TopicName : topic2.TopicName,
								  ContributeId = scheduleInfo.IsContribute ? contribute.ID : scheduleEvent.ID,
								  EssayTitle = scheduleInfo.IsContribute ? contribute.EssayTitle : scheduleEvent.EventName,
								  FullName = author.FullName,
								  //Affiliation = author.Affiliation,
								  Mobile = author.Mobile,
								  Mail = author.Mail,
								  StartTime = scheduleInfo.StartTime.ToString().Substring(0, 5),
								  EndTime = scheduleInfo.EndTime.ToString().Substring(0, 5),
								  Duration = scheduleInfo.Duration,
								  IsContribute = scheduleInfo.IsContribute,
								  IsLock = scheduleInfo.IsLock,
								  Status = scheduleInfo.Status,
								  Remark = scheduleInfo.IsContribute ? contribute.Remark : scheduleEvent.Remark,
								  ConferenceId = contribute.ConferenceId,
								  ScheduleId = scheduleInfo.ScheduleId,
								  ScheduleDate = scheduleInfo.ScheduleDate
							  };

						var sqlResult = await sql.ToListAsync();

						var result = new List<ConferenceScheduleReportModel>();
						sqlResult.ForEach(y =>
						{
							var strAffiliation = string.Empty;
							var strAuthor = string.Empty;
							var strAuthorAffiliation = string.Empty;

							if (y.IsContribute)
							{
								var affiliationList = DbContext.AffiliationInfo.AsNoTracking()
									.Where(x => x.Status == ConstValues.Status.正常 &&
										x.ConferenceId == y.ConferenceId &&
										x.ContributeId == y.ContributeId &&
										x.Mail == y.Mail)
									.OrderBy(x => x.Sort)
									.ThenBy(x => x.Affiliation)
									.ToList();

								foreach (var aff in affiliationList)
								{
									if (!string.IsNullOrEmpty(strAffiliation))
									{
										strAffiliation += ConstValues.strSemicolon + ConstValues.chrSpace;
									}
									strAffiliation += aff.Affiliation;
									if (conferenceMaster.IsInternational)
									{
										var tempCountryId = aff.Country;
										var locationMaster = DbContext.LocationMaster.AsNoTracking().FirstOrDefault(x => x.ID == tempCountryId);
										if (locationMaster != null)
										{
											strAffiliation += ConstValues.strComma + locationMaster.NameEn;
										}
										else
										{
											strAffiliation += string.Empty;
										}
									}
								}

								var authorFormat = Utility.GetAuthorFormat(y.ContributeId);
								strAuthor = authorFormat[0];
								strAuthorAffiliation = authorFormat[1];
							}

							result.Add(new ConferenceScheduleReportModel()
							{
								Id = y.Id,
								ReportType = y.ReportType,
								TopicName = y.TopicName,
								ContributeId = y.IsContribute ? y.ContributeId : string.Empty,
								EssayTitle = y.IsContribute ? y.EssayTitle : Utility.GetScheduleEventNameById(y.ContributeId),
								FullName = y.FullName,
								Affiliation = strAffiliation,
								Mobile = y.Mobile,
								Mail = y.Mail,
								Author = strAuthor,
								AuthorAffiliation = strAuthorAffiliation,
								StartTime = y.StartTime,
								EndTime = y.EndTime,
								Duration = y.Duration,
								IsContribute = y.IsContribute,
								IsLock = y.IsLock,
								Status = y.Status,
								Remark = y.Remark,
								ScheduleId = y.ScheduleId,
								ScheduleDate = y.ScheduleDate
							});
						});
						#endregion

						IRow row = newSheet.CreateRow(rowIndex);
						NPOI.SS.UserModel.ICell cell = row.CreateCell(columnIndex);

						// 专题名称
						cell.SetCellValue(Resources.TopicName + ConstValues.strColon + string.Join(ConstValues.strSemicolon, topicList));

						// 地点
						rowIndex++;
						row = newSheet.CreateRow(rowIndex);
						cell = row.CreateCell(columnIndex);
						cell.SetCellValue(Resources.Location + ConstValues.strColon + scheduleMaster.SchedulePlace);

						// 日期
						rowIndex++;
						row = newSheet.CreateRow(rowIndex);
						cell = row.CreateCell(columnIndex);
						cell.SetCellValue(conferenceMaster.IsInternational ?
								scheduleDateMaster.ScheduleDate.ToString("MMMM dd, yyyy") :
								scheduleDateMaster.ScheduleDate.ToString("yyyy年MM月dd日"));

						foreach (var model in result)
						{
							columnIndex = 0;

							// 时间
							rowIndex++;
							row = newSheet.CreateRow(rowIndex);
							cell = row.CreateCell(columnIndex);
							cell.CellStyle = cellStyle;
							cell.SetCellValue(model.StartTime + ConstValues.strHyphen + model.EndTime);

							// 论文题目(报告类型) 报告人 单位
							columnIndex++;
							cell = row.CreateCell(columnIndex);
							cell.CellStyle = !model.IsContribute ? cellStyle : cellStyle2;
							var hasReportType = true;
							if (model.ReportType == Resources.ScheduleEvent)
							{
								hasReportType = false;
							}else
							{
								hasReportType = true;
							}
							var str = hasReportType ?
										(!model.IsContribute ? model.EssayTitle + ConstValues.strSpace + ConstValues.strLeftBracket + model.ReportType + ConstValues.strRightBracket :
										model.EssayTitle + ConstValues.strSpace + ConstValues.strLeftBracket + model.ReportType + ConstValues.strRightBracket + "\r\n" + model.FullName + "\r\n" + model.Affiliation) :
										(!model.IsContribute ? model.EssayTitle :
										model.EssayTitle +  "\r\n" + model.FullName + "\r\n" + model.Affiliation);


							cell.SetCellValue(str);

							// 论文题目(报告类型)
							columnIndex++;
							cell = row.CreateCell(columnIndex);
							cell.CellStyle = cellStyle;
							var str2 = hasReportType ?
									(model.EssayTitle + ConstValues.strSpace + ConstValues.strLeftBracket + model.ReportType + ConstValues.strRightBracket) :
									model.EssayTitle; 

							cell.SetCellValue(str2);

							// 报告人
							columnIndex++;
							cell = row.CreateCell(columnIndex);
							cell.CellStyle = cellStyle;
							cell.SetCellValue(model.FullName);

							// 单位
							columnIndex++;
							cell = row.CreateCell(columnIndex);
							cell.CellStyle = cellStyle;
							cell.SetCellValue(model.Affiliation);

							// 手机
							columnIndex++;
							cell = row.CreateCell(columnIndex);
							cell.CellStyle = cellStyle;
							cell.SetCellValue(model.Mobile);

							// 邮箱
							columnIndex++;
							cell = row.CreateCell(columnIndex);
							cell.CellStyle = cellStyle;
							cell.SetCellValue(model.Mail);

							// 所有作者
							columnIndex++;
							cell = row.CreateCell(columnIndex);
							cell.CellStyle = cellStyle;
							var author = model.Author;
							List<int[]> tagIndexArr = new List<int[]>();
							if (Utility.ContainSubSup(author))
							{
								author = Utility.GetSupIndexs(author, ref tagIndexArr);
							}

							if (tagIndexArr.Count > 0)
							{
								XSSFRichTextString text = new XSSFRichTextString(author);
								if (tagIndexArr.Count() > 0)
								{
									IFont ft = workbook.CreateFont();
									ft.TypeOffset = FontSuperScript.Super;
									foreach (int[] pair in tagIndexArr)
									{
										text.ApplyFont(pair[0], pair[1], ft);
									}
								}
								cell.SetCellValue(text);
							}
							else
							{
								cell.SetCellValue(author);
							}

							// 所有作者单位
							columnIndex++;
							cell = row.CreateCell(columnIndex);
							cell.CellStyle = cellStyle;
							cell.SetCellValue(model.AuthorAffiliation);

							// 稿件编号
							columnIndex++;
							cell = row.CreateCell(columnIndex);
							cell.CellStyle = cellStyle;
							cell.SetCellValue(model.ContributeId);
						}

						rowIndex += 3;
					}
					#endregion
				}

				if (workbook.NumberOfSheets > 1)
				{
					workbook.SetSheetHidden(0, 2);
				}
			}

			MemoryStream exportStream = new MemoryStream();
			workbook.Write(exportStream);
			exportStream.Flush();
			exportStream.Position = 0;

			return File(exportStream, Application.Octet,
					$"export_scheduleInfo_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
		}
		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<FileResult> ExportPoster(string conferenceId)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", conferenceId);

			var sql = from contribute in DbContext.ConferenceContributeInfo.AsNoTracking()
					.Where(x => x.IsConfirm &&
						x.ConferenceId == conferenceId &&
						(!string.IsNullOrEmpty(x.AdminStatus) ? x.AdminStatus == ConstValues.ContributationStatus.录用 :
							x.ContributationStatus == ConstValues.ContributationStatus.录用))
				  join topicMaster in DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					  on contribute.TopicId equals topicMaster.ID
				  join reportMaster in DbContext.ReportMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常 &&
						(x.ReportType == ConstValues.PosterCn || x.ReportType == ConstValues.PosterEn))
					  on contribute.ReportId equals reportMaster.ID
				  orderby contribute.ID
				  select new
				  {
					  ContributeId = contribute.ID,
					  EssayTitle = contribute.EssayTitle,
					  Abstract = contribute.Abstract,
					  ProgramAbstract = contribute.ProgramAbstract,
					  Keyword = contribute.Keyword,
					  TopicName = topicMaster.TopicName,
				  };

			var sqlResult = await sql.ToListAsync();

			var result = new List<ConferenceScheduleReportModel>();
			sqlResult.ForEach(y =>
			{
				var authorFormat = Utility.GetAuthorFormat(y.ContributeId);
				var strAuthor = authorFormat[0];
				var strAuthorAffiliation = authorFormat[1];

				result.Add(new ConferenceScheduleReportModel()
				{
					ContributeId = y.ContributeId,
					EssayTitle = y.EssayTitle,
					Author = strAuthor,
					AuthorAffiliation = strAuthorAffiliation,
					Abstract = y.Abstract,
					ProgramAbstract = y.ProgramAbstract,
					Keyword = y.Keyword,
					TopicName = y.TopicName
				});
			});

			var export = Request.Cookies["_culture"].Value == ConstValues.Language.Cn ?
					Resources.export_posterCN : Resources.export_posterEN;

			XSSFWorkbook workbook;

			using (MemoryStream readStream = new MemoryStream(export))
			{
				workbook = new XSSFWorkbook(readStream);
				ISheet sheet = workbook.GetSheetAt(0);
				ICellStyle cellStyle = workbook.CreateCellStyle();
				cellStyle.VerticalAlignment = VerticalAlignment.Center;
				cellStyle.WrapText = true;

				var count = 0;
				foreach (var model in result)
				{
					count += 1;
					IRow row = sheet.CreateRow(count);

					// 稿号
					int column = 0;
					NPOI.SS.UserModel.ICell cell = row.CreateCell(column);
					cell.CellStyle = cellStyle;
					cell.SetCellValue(model.ContributeId);

					// 所有作者
					var author = model.Author;
					List<int[]> tagIndexArr = new List<int[]>();
					if (Utility.ContainSubSup(author))
					{
						author = Utility.GetSupIndexs(author, ref tagIndexArr);
					}

					if (tagIndexArr.Count > 0)
					{
						XSSFRichTextString text = new XSSFRichTextString(author);
						if (tagIndexArr.Count() > 0)
						{
							IFont ft = workbook.CreateFont();
							ft.TypeOffset = FontSuperScript.Super;
							foreach (int[] pair in tagIndexArr)
							{
								text.ApplyFont(pair[0], pair[1], ft);
							}
						}
						author = text.String;
					}

					// 论文题目(报告类型) 报告人 单位
					column++;
					cell = row.CreateCell(column);
					cell.CellStyle = cellStyle;
					cell.SetCellValue(Utility.ChangeSubSupForExcel(workbook, model.EssayTitle + "\r\n" + model.Author + "\r\n" + model.AuthorAffiliation));
					
					// 全文摘要
					column++;
					cell = row.CreateCell(column);
					cell.CellStyle = cellStyle;
					cell.SetCellValue(!string.IsNullOrEmpty(model.Abstract) ? Utility.ChangeSubSupForExcel(workbook,model.Abstract) : new XSSFRichTextString(""));

					// 日程摘要
					column++;
					cell = row.CreateCell(column);
					cell.CellStyle = cellStyle;
					cell.SetCellValue(!string.IsNullOrEmpty(model.ProgramAbstract) ? Utility.ChangeSubSupForExcel(workbook,model.ProgramAbstract) : new XSSFRichTextString(""));

					// 关键词
					column++;
					cell = row.CreateCell(column);
					cell.CellStyle = cellStyle;
					cell.SetCellValue(model.Keyword);

					// 专题名称
					column++;
					cell = row.CreateCell(column);
					cell.CellStyle = cellStyle;
					cell.SetCellValue(model.TopicName);

					// 题目
					column++;
					cell = row.CreateCell(column);
					cell.CellStyle = cellStyle;
					cell.SetCellValue(model.EssayTitle);

					// 所有作者
					column++;
					cell = row.CreateCell(column);
					cell.CellStyle = cellStyle;
					cell.SetCellValue(Utility.ChangeSubSupForExcel(workbook, model.Author));

					// 单位
					column++;
					cell = row.CreateCell(column);
					cell.CellStyle = cellStyle;
					cell.SetCellValue(model.AuthorAffiliation);
				}
			}

			MemoryStream exportStream = new MemoryStream();
			workbook.Write(exportStream);
			exportStream.Flush();
			exportStream.Position = 0;

			return File(exportStream, Application.Octet,
					$"export_poster_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
		}
		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<ActionResult> ExportProgramAbstract(string conferenceId)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", conferenceId);

			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == conferenceId &&
						x.Status == ConstValues.Status.正常);
			string folder = Server.MapPath(Path.Combine(ConstValues.Uploads, conferenceMaster.ConferenceNickName));

			var scheduleMasterList = await DbContext.ScheduleMaster.AsNoTracking()
					.Where(x => x.ConferenceId == conferenceId &&
						x.Status == ConstValues.Status.正常)
					.OrderBy(x => x.Sort)
					.ThenBy(x => x.SchedulePlace)
					.ThenByDescending(x => x.UpdateDate)
					.ToListAsync();
			
			foreach (var scheduleMaster in scheduleMasterList)
			{
				XWPFDocument doc = new XWPFDocument();
				var scheduleDateMasterList = DbContext.ScheduleDateMaster.AsNoTracking()
						.Where(x => x.ScheduleId == scheduleMaster.ID &&
							x.Status == ConstValues.Status.正常)
						.OrderBy(x => x.ScheduleDate)
						.ToList();

				#region 地点区分
				foreach (var scheduleDateMaster in scheduleDateMasterList)
				{
					var topicList = DbContext.ScheduleTopicMaster.AsNoTracking()
							.Where(x => x.Status == ConstValues.Status.正常 &&
								x.ScheduleId == scheduleDateMaster.ScheduleId &&
								x.ScheduleDate == scheduleDateMaster.ScheduleDate)
							.Join(DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常),
								schedule => schedule.TopicId,
								topic => topic.ID,
								(schedule, topic) => new
								{
									TopicName = topic.TopicName
								})
							.OrderBy(x => x.TopicName)
							.Select(x => x.TopicName)
							.ToList();

					#region 日期区分
					var sql = from scheduleInfo in DbContext.ScheduleInfo.AsNoTracking()
							.Where(x => x.ScheduleId == scheduleMaster.ID &&
								x.ScheduleDate == scheduleDateMaster.ScheduleDate &&
								x.IsContribute == true)
						  join contribute in DbContext.ConferenceContributeInfo.AsNoTracking()
							  on scheduleInfo.ContributeId equals contribute.ID
						  join authorInfo in DbContext.AuthorInfo.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常 && x.IsPresenter)
							  on contribute.ID equals authorInfo.ContributeId into t2
						  from author in t2.DefaultIfEmpty()
						  join reportMaster in DbContext.ReportMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
							  on contribute.ReportId equals reportMaster.ID into t3
						  from report in t3.DefaultIfEmpty()
						  join topicMaster in DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
							  on contribute.TopicId equals topicMaster.ID into t4
						  from topic in t4.DefaultIfEmpty()
						  orderby scheduleInfo.StartTime, scheduleInfo.EndTime
						  select new
						  {
							  ConferenceId = contribute.ConferenceId,
							  ContributeId = contribute.ID,
							  EssayTitle = contribute.EssayTitle,
							  ReportType = report.ReportType,
							  TopicName = topic.TopicName,
							  Keyword = contribute.Keyword,
							  Abstract = contribute.Abstract,
							  ProgramAbstract = contribute.ProgramAbstract,
							  Mail = author.Mail,
							  SelfIntroduction = author.SelfIntroduction,
							  StartTime = scheduleInfo.StartTime.ToString().Substring(0, 5),
							  EndTime = scheduleInfo.EndTime.ToString().Substring(0, 5),
							  ScheduleId = scheduleInfo.ScheduleId,
							  ScheduleDate = scheduleInfo.ScheduleDate,
							  HasAbstract = report ==null ? false : report.HasAbstract,
							  HasProgramAbstract = report == null ? false : report.HasProgramAbstract
						  };

					var sqlResult = await sql.ToListAsync();

					var result = new List<ConferenceScheduleReportModel>();
					sqlResult.ForEach(y =>
					{
						var authorFormat = Utility.GetAuthorFormat(y.ContributeId);
						var strAuthor = authorFormat[0];
						var strAuthorAffiliation = authorFormat[1];

						var affiliationList = DbContext.AffiliationInfo.AsNoTracking()
							.Where(x => x.Status == ConstValues.Status.正常 &&
								x.ConferenceId == y.ConferenceId &&
								x.ContributeId == y.ContributeId &&
								x.Mail == y.Mail)
							.OrderBy(x => x.Sort)
							.ThenBy(x => x.Affiliation)
							.Select(x => new
							{
								Affiliation = x.Affiliation,
								Country = x.Country
							})
							.Distinct()
							.ToList();
						var affiliation = string.Empty;
						if (affiliationList.Count > 0)
						{
							foreach (var x in affiliationList)
							{
								if (!string.IsNullOrEmpty(affiliation))
								{
									affiliation += ConstValues.strSemicolon;
								}
								affiliation += x.Affiliation;
								if (conferenceMaster.IsInternational)
								{
									affiliation += ConstValues.strComma + DbContext.LocationMaster.AsNoTracking().FirstOrDefault(z => z.ID == x.Country)?.NameEn;
								}
							}
						}

						result.Add(new ConferenceScheduleReportModel()
						{
							ContributeId = y.ContributeId,
							EssayTitle = y.EssayTitle,
							ReportType = y.ReportType,
							TopicName = y.TopicName,
							Keyword = y.Keyword,
							Abstract = y.Abstract,
							SelfIntroduction = y.SelfIntroduction,
							Author = strAuthor,
							Affiliation = affiliation,
							AuthorAffiliation = strAuthorAffiliation,
							StartTime = y.StartTime,
							EndTime = y.EndTime,
							ScheduleDate = y.ScheduleDate,
							ProgramAbstract = y.ProgramAbstract,
							HasAbstract = y.HasAbstract,
							HasProgramAbstract = y.HasProgramAbstract
						});
					});
					#endregion

					if (sqlResult.Count > 0)
					{
						XWPFParagraph paragraph = doc.CreateParagraph();
						paragraph.Alignment = ParagraphAlignment.LEFT;

						// 专题名称
						XWPFRun run = paragraph.CreateRun();
						run.SetText(Resources.TopicName + ConstValues.strColon + string.Join(ConstValues.strSemicolon, topicList));
						run.FontSize = 10;
						run.AddCarriageReturn();

						// 地点
						run = paragraph.CreateRun();
						run.SetText(Resources.Place + ConstValues.strColon + scheduleMaster.SchedulePlace);
						run.FontSize = 10;
						run.AddCarriageReturn();
						run.AddCarriageReturn();

						// 日期
						run = paragraph.CreateRun();
						run.SetText(conferenceMaster.IsInternational ?
								scheduleDateMaster.ScheduleDate.ToString("MMMM dd, yyyy") :
								scheduleDateMaster.ScheduleDate.ToString("yyyy年MM月dd日"));
						run.FontSize = 10;
						run.AddCarriageReturn();
						run.AddCarriageReturn();
						run.AddCarriageReturn();

						foreach (var model in result)
						{
							// 稿件编号
							run = paragraph.CreateRun();
							run.SetText(Resources.ContributionID + ConstValues.strColon + model.ContributeId);
							run.FontSize = 10;
							run.AddCarriageReturn();

							// 时间(报告类型)
							run = paragraph.CreateRun();
							run.SetText(model.StartTime + ConstValues.strHyphen + model.EndTime + ConstValues.strSpace + ConstValues.strLeftBracket + model.ReportType + ConstValues.strRightBracket);
							run.FontSize = 10;
							run.AddCarriageReturn();

							// 题目
							run = paragraph.CreateRun();
							run.SetText(model.EssayTitle);
							run.FontSize = 10;
							run.AddCarriageReturn();

							// 作者
							var allAuthor = model.Author;
							if (Utility.ContainSubSup(allAuthor))
							{
								do
								{
									var indexStart = allAuthor.IndexOf(ConstValues.strHtmlSupStart);
									var author = allAuthor.Substring(0, indexStart);
									run = paragraph.CreateRun();
									run.SetText(author);
									run.FontSize = 10;
									allAuthor = allAuthor.Substring(indexStart + ConstValues.strHtmlSupStart.Length);

									var indexEnd = allAuthor.IndexOf(ConstValues.strHtmlSupEnd);
									var tmp = allAuthor.Substring(0, indexEnd);
									run = paragraph.CreateRun();
									run.FontSize = 10;
									CT_RPr rpr = run.GetCTR().AddNewRPr();
									rpr.vertAlign = new CT_VerticalAlignRun();
									rpr.vertAlign.val = ST_VerticalAlignRun.superscript;
									run.SetText(tmp);

									allAuthor = allAuthor.Substring(indexEnd + ConstValues.strHtmlSupEnd.Length);
								}
								while (Utility.ContainSubSup(allAuthor));
								run.AddCarriageReturn();
							}
							else
							{
								run = paragraph.CreateRun();
								run.SetText(model.Author);
								run.FontSize = 10;
								run.AddCarriageReturn();
							}

							// 单位
							if (!string.IsNullOrEmpty(model.AuthorAffiliation))
							{
								var affiliationNameList = model.AuthorAffiliation.Split(new string[] {
										conferenceMaster.IsInternational ? (ConstValues.strSemicolon + ConstValues.chrSpace) : (ConstValues.strSemicolonCN)
										}, StringSplitOptions.None);
								for (var index = 0; index < affiliationNameList.Length; index++)
								{
									run = paragraph.CreateRun();
									run.SetText(affiliationNameList[index]);
									run.FontSize = 10;

									if (index != affiliationNameList.Length - 1)
									{
										if (conferenceMaster.IsInternational)
										{
											run.AppendText(ConstValues.strSemicolon);
										}
										else
										{
											run.AppendText(ConstValues.strSemicolonCN);
										}
									}
									run.AddCarriageReturn();
								}
								run.AddCarriageReturn();
								run.AddCarriageReturn();
							}
							else if (!string.IsNullOrEmpty(model.Affiliation))
							{
								run = paragraph.CreateRun();
								run.SetText(model.Affiliation);
								run.FontSize = 10;
								run.AddCarriageReturn();
								run.AddCarriageReturn();
							}else
							{
								run.AddCarriageReturn();
								run.AddCarriageReturn();
							}

							// 日程摘要
							if (model.HasProgramAbstract)
							{
								if (!string.IsNullOrEmpty(model.ProgramAbstract))
								{
									if (Utility.ContainSubSup(model.ProgramAbstract))
									{
										run = Utility.ChangeSubSupForWord(paragraph, run, Resources.ProgramAbstract + ConstValues.strColon + ConstValues.chrSpace + model.ProgramAbstract);
										run.AddCarriageReturn();
									}
									else
									{
										run = paragraph.CreateRun();
										run.SetText(Resources.ProgramAbstract + ConstValues.strColon + Utility.GetNoHtml(model.ProgramAbstract));
										run.FontSize = 10;
										run.AddCarriageReturn();
									}
								}
								else
								{
									run.AddCarriageReturn();
								}
							}

							// 全文摘要
							if (model.HasAbstract)
							{
								if (!string.IsNullOrEmpty(model.Abstract))
								{
									if (Utility.ContainSubSup(model.Abstract))
									{
										run = Utility.ChangeSubSupForWord(paragraph, run, Resources.OnlyAbstract + ConstValues.strColon + ConstValues.chrSpace + model.Abstract);
										run.AddCarriageReturn();

									}
									else
									{
										run = paragraph.CreateRun();
										run.SetText(Resources.OnlyAbstract + ConstValues.strColon + Utility.GetNoHtml(model.Abstract));
										run.FontSize = 10;
										run.AddCarriageReturn();
									}
								}
								else
								{
									run.AddCarriageReturn();
								}
							}

							// 关键词
							if (!string.IsNullOrEmpty(model.Keyword))
							{
								run = paragraph.CreateRun();
								run.SetText(Resources.Keyword + ConstValues.strColon + model.Keyword);
								run.FontSize = 10;
								run.AddCarriageReturn();
								run.AddCarriageReturn();
							}
							else
							{
								run.AddCarriageReturn();
							}

							// 个人简介
							if (!string.IsNullOrEmpty(model.SelfIntroduction))
							{
								run = paragraph.CreateRun();
								run.SetText(Resources.PersonalIntroduction + ConstValues.strColon + model.SelfIntroduction);
								run.FontSize = 10;
								run.AddCarriageReturn();
								run.AddCarriageReturn();
								run.AddCarriageReturn();
							}
							else
							{
								run.AddCarriageReturn();
								run.AddCarriageReturn();
							}

						}
					}
					
				}
				#endregion

				FileStream sw = System.IO.File.Create(Path.Combine(folder, scheduleMaster.SchedulePlace + ".docx"));
				doc.Write(sw);
				sw.Close();
			}

			Encoding gbk = Encoding.GetEncoding("gbk");

			ZipConstants.DefaultCodePage = gbk.CodePage;
			MemoryStream memoryStream = new MemoryStream();
			
			using (ZipOutputStream zipStream = new ZipOutputStream(memoryStream))
			{
				zipStream.SetLevel(3);
				foreach (var scheduleMaster in scheduleMasterList)
				{
					var newFile = Path.Combine(folder, scheduleMaster.SchedulePlace + ".docx");
					ZipEntry newEntry = new ZipEntry(Path.GetFileName(newFile));
					FileInfo fi = new FileInfo(newFile);
					newEntry.DateTime = fi.LastWriteTime;
					newEntry.Size = fi.Length;
					zipStream.PutNextEntry(newEntry);
					using (FileStream streamReader = System.IO.File.OpenRead(newFile))
					{
						StreamUtils.Copy(streamReader, zipStream, new byte[4096]);
					}
					zipStream.CloseEntry();
					System.IO.File.Delete(Path.Combine(folder, scheduleMaster.SchedulePlace + ".docx"));
				}

				zipStream.IsStreamOwner = false;
				zipStream.Close();

				memoryStream.Position = 0;
				var downloadFileName = "export_programAbstract_"+conferenceMaster.ConferenceNickName + ConstValues.chrUnderline
							+ DateTime.Now.ToString("yyyyMMddHHmm")
							+ ".zip";
				return File(memoryStream, Application.Octet, downloadFileName);
			}
		}

		private bool CheckScheduleDate(ConferenceScheduleDateModel model, TimeSpan time)
		{
			if ((model.ForenoonStartTime.HasValue && time < model.ForenoonStartTime.Value) ||
				(model.EveningEndTime.HasValue && time > model.EveningEndTime.Value))
			{
				return false;
			}

			if ((!model.ForenoonEndTime.HasValue || (model.ForenoonEndTime.HasValue && time > model.ForenoonEndTime.Value)) &&
				(!model.AfternoonStartTime.HasValue || (model.AfternoonStartTime.HasValue && time < model.AfternoonStartTime.Value)))
			{
				return false;
			}

			if ((!model.AfternoonEndTime.HasValue || (model.AfternoonEndTime.HasValue && time > model.AfternoonEndTime.Value)) &&
				(!model.EveningStartTime.HasValue || (model.EveningStartTime.HasValue && time < model.EveningStartTime.Value)))
			{
				return false;
			}

			return true;
		}

		/// <summary>
		/// 日程日期验证
		/// </summary>
		/// <param name="scheduleDateMaster"></param>
		/// <returns></returns>
		private bool CheckSchedule(ScheduleDateMaster scheduleDateMaster)
		{
			if (scheduleDateMaster.ForenoonStartTime.HasValue)
			{
				// 上午有时间区间
				this._durationForenoon = scheduleDateMaster.ForenoonEndTime.Value.TotalMinutes - scheduleDateMaster.ForenoonStartTime.Value.TotalMinutes;
			}
			if (scheduleDateMaster.AfternoonStartTime.HasValue)
			{
				// 下午有时间区间
				this._durationAfternoon = scheduleDateMaster.AfternoonEndTime.Value.TotalMinutes - scheduleDateMaster.AfternoonStartTime.Value.TotalMinutes;
			}
			if (scheduleDateMaster.EveningStartTime.HasValue)
			{
				// 晚上有时间区间
				this._durationEvening = scheduleDateMaster.EveningEndTime.Value.TotalMinutes - scheduleDateMaster.EveningStartTime.Value.TotalMinutes;
			}
			if (this._durationForenoon == 0 && this._durationAfternoon == 0 && this._durationEvening == 0)
			{
				return false;
			}

			return true;
		}

		/// <summary>
		/// 状态验证
		/// </summary>
		/// <param name="scheduleInfo"></param>
		/// <param name="mode"></param>
		/// <returns></returns>
		private string CheckScheduleInfo(ScheduleInfo scheduleInfo)
		{
			if (scheduleInfo.Status == ConstValues.ScheduleStatus.已取消)
			{
				return Resources.MsgCancelCanNotChange;
			}
			else if (scheduleInfo.IsLock)
			{
				return Resources.MsgLockCanNotChange;
			}

			return string.Empty;
		}

		/// <summary>
		/// 开始时间验证
		/// </summary>
		/// <param name="scheduleDateMaster"></param>
		/// <param name="duration"></param>
		/// <returns></returns>
		private bool CheckMoveStartTime(ScheduleDateMaster scheduleDateMaster, double duration)
		{
			if (this._durationForenoon != 0 && this._startTime <= scheduleDateMaster.ForenoonEndTime.Value)
			{
				if (this._startTime >= scheduleDateMaster.ForenoonStartTime.Value &&
					this._startTime.Add(TimeSpan.FromMinutes(duration)) <= scheduleDateMaster.ForenoonEndTime.Value)
				{
					return true;
				}
			}

			if (this._durationAfternoon != 0 && this._startTime <= scheduleDateMaster.AfternoonEndTime.Value)
			{
				if (this._startTime >= scheduleDateMaster.AfternoonStartTime.Value &&
					this._startTime.Add(TimeSpan.FromMinutes(duration)) <= scheduleDateMaster.AfternoonEndTime.Value)
				{
					return true;
				}
			}

			if (this._durationEvening != 0 && this._startTime <= scheduleDateMaster.EveningEndTime.Value)
			{
				if (this._startTime >= scheduleDateMaster.EveningStartTime.Value &&
					this._startTime.Add(TimeSpan.FromMinutes(duration)) <= scheduleDateMaster.EveningEndTime.Value)
				{
					return true;
				}
			}

			return false;
		}

		/// <summary>
		/// 获取开始时间
		/// </summary>
		/// <param name="scheduleDateMaster"></param>
		/// <param name="scheduleInfoList"></param>
		/// <param name="srcInfo"></param>
		/// <param name="desInfo"></param>
		/// <returns></returns>
		private bool CheckStartTime(ScheduleDateMaster scheduleDateMaster, List<ScheduleInfo> scheduleInfoList, ScheduleInfo srcInfo, ScheduleInfo desInfo = null)
		{
			double beginTime = 0;
			double finishTime = 0;
			
			if (this._durationForenoon != 0 && this._startTime < scheduleDateMaster.ForenoonEndTime.Value)
			{
				// 上午时间区间足够，安排在上午
				beginTime = this._startTime > scheduleDateMaster.ForenoonStartTime.Value ? this._startTime.TotalMinutes :
						scheduleDateMaster.ForenoonStartTime.Value.TotalMinutes;
				finishTime = scheduleDateMaster.ForenoonEndTime.Value.Add(TimeSpan.FromMinutes(srcInfo.Duration * -1)).TotalMinutes;

				for (var time = beginTime; time <= finishTime; time++)
				{
					var sql = scheduleInfoList.Where(x => x.ID != srcInfo.ID &&
							((x.StartTime.TotalMinutes <= time && x.EndTime.TotalMinutes > time) ||
							(x.StartTime.TotalMinutes < time + srcInfo.Duration && x.EndTime.TotalMinutes >= time + srcInfo.Duration)));

					if (desInfo != null && desInfo.Duration != 0)
					{
						sql = sql.Where(x => x.ID != desInfo.ID);
					}

					var sqlResult = sql.ToList();

					if (sqlResult.Count() == 0)
					{
						this._startTime = TimeSpan.FromMinutes(time);
						return true;
					}
				}
			}
			if (this._durationAfternoon != 0 && this._startTime < scheduleDateMaster.AfternoonEndTime.Value)
			{
				// 下午时间区间足够，安排在下午
				beginTime = this._startTime > scheduleDateMaster.AfternoonStartTime.Value ? this._startTime.TotalMinutes :
						scheduleDateMaster.AfternoonStartTime.Value.TotalMinutes;
				finishTime = scheduleDateMaster.AfternoonEndTime.Value.Add(TimeSpan.FromMinutes(srcInfo.Duration * -1)).TotalMinutes;

				for (var time = beginTime; time <= finishTime; time++)
				{
					var sql = scheduleInfoList.Where(x => x.ID != srcInfo.ID &&
							((x.StartTime.TotalMinutes <= time && x.EndTime.TotalMinutes > time) ||
							(x.StartTime.TotalMinutes < time + srcInfo.Duration && x.EndTime.TotalMinutes >= time + srcInfo.Duration)));

					if (desInfo != null && desInfo.Duration != 0)
					{
						sql = sql.Where(x => x.ID != desInfo.ID);
					}

					var sqlResult = sql.ToList();

					if (sqlResult.Count() == 0)
					{
						this._startTime = TimeSpan.FromMinutes(time);
						return true;
					}
				}
			}
			if (this._durationEvening != 0 && this._startTime < scheduleDateMaster.EveningEndTime.Value)
			{
				// 晚上时间区间足够，安排在晚上
				beginTime = this._startTime > scheduleDateMaster.EveningStartTime.Value ? this._startTime.TotalMinutes :
						scheduleDateMaster.EveningStartTime.Value.TotalMinutes;
				finishTime = scheduleDateMaster.EveningEndTime.Value.Add(TimeSpan.FromMinutes(srcInfo.Duration * -1)).TotalMinutes;

				for (var time = beginTime; time <= finishTime; time++)
				{
					var sql = scheduleInfoList.Where(x => x.ID != srcInfo.ID &&
							((x.StartTime.TotalMinutes <= time && x.EndTime.TotalMinutes > time) ||
							(x.StartTime.TotalMinutes < time + srcInfo.Duration && x.EndTime.TotalMinutes >= time + srcInfo.Duration)));

					if (desInfo != null && desInfo.Duration != 0)
					{
						sql = sql.Where(x => x.ID != desInfo.ID);
					}

					var sqlResult = sql.ToList();

					if (sqlResult.Count() == 0)
					{
						this._startTime = TimeSpan.FromMinutes(time);
						return true;
					}
				}
			}
			return false;
		}

		private bool CheckStartTimeForReset(ScheduleDateMaster scheduleDateMaster, List<ScheduleInfo> scheduleInfoList, ScheduleInfo srcInfo, ScheduleInfo desInfo = null)
		{
			double beginTime = 0;
			double finishTime = 0;

			if (this._durationForenoon != 0 && this._startTime <= scheduleDateMaster.ForenoonEndTime.Value &&
				this._startTime <= scheduleDateMaster.ForenoonEndTime.Value.Add(TimeSpan.FromMinutes(srcInfo.Duration * -1)))
			{
				// 上午时间区间足够，安排在上午
				beginTime = this._startTime > scheduleDateMaster.ForenoonStartTime.Value ? this._startTime.TotalMinutes :
						scheduleDateMaster.ForenoonStartTime.Value.TotalMinutes;
				finishTime = scheduleDateMaster.ForenoonEndTime.Value.Add(TimeSpan.FromMinutes(srcInfo.Duration * -1)).TotalMinutes;
				
				this._startTime = TimeSpan.FromMinutes(scheduleDateMaster.ForenoonStartTime.Value.TotalMinutes);
				return true;
					
			}
			if (this._durationAfternoon != 0 && this._startTime <= scheduleDateMaster.AfternoonEndTime.Value &&
				this._startTime <= scheduleDateMaster.AfternoonEndTime.Value.Add(TimeSpan.FromMinutes(srcInfo.Duration * -1)))
			{
				// 下午时间区间足够，安排在下午
				beginTime = this._startTime > scheduleDateMaster.AfternoonStartTime.Value ? this._startTime.TotalMinutes :
						scheduleDateMaster.AfternoonStartTime.Value.TotalMinutes;
				finishTime = scheduleDateMaster.AfternoonEndTime.Value.Add(TimeSpan.FromMinutes(srcInfo.Duration * -1)).TotalMinutes;

				this._startTime = TimeSpan.FromMinutes(scheduleDateMaster.AfternoonStartTime.Value.TotalMinutes);
				return true;
					
				
			}
			if (this._durationEvening != 0 && this._startTime < scheduleDateMaster.EveningEndTime.Value &&
				this._startTime < scheduleDateMaster.EveningEndTime.Value.Add(TimeSpan.FromMinutes(srcInfo.Duration * -1)))
			{
				// 晚上时间区间足够，安排在晚上
				beginTime = this._startTime > scheduleDateMaster.EveningStartTime.Value ? this._startTime.TotalMinutes :
						scheduleDateMaster.EveningStartTime.Value.TotalMinutes;
				finishTime = scheduleDateMaster.EveningEndTime.Value.Add(TimeSpan.FromMinutes(srcInfo.Duration * -1)).TotalMinutes;

				this._startTime = TimeSpan.FromMinutes(scheduleDateMaster.EveningStartTime.Value.TotalMinutes);
				return true;
					
			}
			return false;
		}

		/// <summary>
		/// 更新稿件表或日程环节管理表
		/// </summary>
		/// <param name="isContribute"></param>
		/// <param name="contributeId"></param>
		/// <param name="scheduleStatus"></param>
		private void UpdateContributeOrEvent(bool isContribute, string contributeId, string scheduleStatus)
		{
			if (isContribute)
			{
				var conferenceContributeInfo = DbContext.ConferenceContributeInfo
						.FirstOrDefault(x => x.ID == contributeId);
				conferenceContributeInfo.ScheduleStatus = scheduleStatus;
				conferenceContributeInfo.Updater = LoginUser.UserName;
				conferenceContributeInfo.UpdateIP = LoginUser.IP;
				conferenceContributeInfo.UpdateDate = DateTime.Now;
			}
			else
			{
				var scheduleEventMaster = DbContext.ScheduleEventMaster
						.FirstOrDefault(x => x.ID == contributeId);
				scheduleEventMaster.ScheduleStatus = scheduleStatus;
				scheduleEventMaster.Updater = LoginUser.UserName;
				scheduleEventMaster.UpdateIP = LoginUser.IP;
				scheduleEventMaster.UpdateDate = DateTime.Now;
			}
		}

		/// <summary>
		/// 根据schedule取对应的专题
		/// </summary>
		/// <returns></returns>
		public async Task<JsonResult> GetTopicWithSchedule(string scheduleId,string scheduleDateId)
		{
			var date = DbContext.ScheduleDateMaster.FirstOrDefault(x => x.ID == scheduleDateId)?.ScheduleDate;

			var result = await DbContext.ScheduleTopicMaster.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ScheduleId == scheduleId && x.ScheduleDate == date)
					.Join(DbContext.TopicMaster.AsNoTracking(),
						scheduleTopicMaster => scheduleTopicMaster.TopicId,
						topicMaster => topicMaster.ID,
						(scheduleTopicMaster, topicMaster) => new
						{
							Id = topicMaster.ID,
							Name = topicMaster.TopicName,
							Sort = topicMaster.Sort
						})

					.OrderBy(x => x.Sort)
					.ThenBy(x => x.Name)
					.Select(x => new
					{
						Id = x.Id,
						Name = x.Name
					})
					.ToListAsync();

			result.Insert(0, new
			{
				Id = string.Empty,
				Name = Resources.All
			});

			return JsonCamelCase(result, JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("DeleteChairman/{ConferenceId}")]
		public async Task<JsonResult> DeleteChairman(ConferenceScheduleInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId); ;

			var result = await DbContext.ScheduleEventMaster
					.FirstOrDefaultAsync(x => x.ID == model.ChairmanId);

			if (result != null)
			{
				if(result.ScheduleStatus == ConstValues.ScheduleStatus.已安排)
				{
					return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgUsingCanNotDelete),
						JsonRequestBehavior.AllowGet);
				}

				DbContext.ScheduleEventMaster.Remove(result);

				await DbContext.SaveChangesAsync();

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessDelete),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}
	}
}